Re: Re: dynamic object instances
| From: | Eli | Date: | Thu, 11 Aug 2005 02:23:39 +0000 |
| Subject: | Re: Re: dynamic object instances | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-220398@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
Eli wrote:I guess that it would be better if PHP will add a possibility to construct a dynamic class with variant number of params... ;-)<? $obj_eval="return new $class("; for ($i=0; $i<count($args); $i++) $obj_eval.="\$args[$i],"; $obj_eval=substr($obj_eval,0,-1).");"; $obj=eval($obj_eval); ?>I believe that this is the kind of clever, evil stuff the OP was trying to avoid... (evil - eval :-) - besides eval is very slow - not something you (well me then) want to use in a function dedicated to object creation which is comparatively slow anyway (try comparing the speed of cloning and creating objects in php5 for instance regardless - nice one for posting this Eli - I recommend anyone who doesn't understand what he wrote to go and figure it out, good learning material :-)You're right that using eval() slows.. But using the _init() function as you suggested is actually tricking in a way you move the constructor params to another function, but the initialization params should be sent to the constructor!