| 
	
 | 
 Posted by jussist@gmail.com on 01/04/07 06:54 
> is it possible to dynamically create function? so I only need to 
> declare one setter, and one getter? 
 
I have used two solutions for that. I have somewhere a script, to which 
you input your fieldnames in a form, and the script generates the class 
skeleteon, with fields, getters, setters and indentation. 
 
Field $name becomes function getName() and setName($param) etc.. 
 
I've also done a helper, which did all that from database, but I think 
that was in java and few years back. I can try and remember to post 
that script here, if I remember when I go to the office. That will be 
earliest saturday, latest next wednesday. 
 
Writing that kind of script is actually not that huge task. 
 
$src = "Class " . $_POST["class_name"]. " { \n\n"; 
$src .= "\t\$" . $fieldname . ";\n\n"; 
$src .= "\tget" . ucfirst($fieldname) . "() {\n"; 
$src .= "\t\treturn \$this->" . $fieldname . ";\n"; 
 
And so on. Just output that and copy/paste - or generate the file with 
your script. 
 
Jussi
 
[Back to original message] 
 |