Re: variable object creating
| From: | olivier | Date: | Wed, 22 Jun 2005 08:21:40 +0000 |
| Subject: | Re: variable object creating | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-217390@lists.php.net to get a copy of this message | ||
Hi,
Try something like:
$classname = "MyClass";
$construct_params = array("param1","param2","param3");
$return =null;
if(class_exists($classname)){
$param=explode(" ',' ", $construct_param);
# You must add here some security checks....
eval("$retrun = new $className($param)");
var_dump($return);
}
Hope this help!
Olivier
Le Mercredi 22 Juin 2005 05:33, Eli a écrit :
> Hi,
>
> I want to create an object in a form that I get the class name and its
> parameters, and I need to create that object...
> How can this been done?
>
> i.e:
> $classname = "MyClass";
> $construct_params = array("param1","param2","param3");
> /* Now create the object with the given classname and params... how? */
>
> -thanks, Eli