Re: variable object creating

From: Date: Thu, 23 Jun 2005 01:17:42 +0000
Subject: Re: variable object creating
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-217451@lists.php.net to get a copy of this message
On Tue, June 21, 2005 8:33 pm, Eli said: > 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? */ Did you try: $instance = new $classname($param1, $param2, $param3); Or do you really need the parameters in an array?... You could maybe use call_user_func_array or whatever it is, and write a tiny function that calls new on the arguments... -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#217451) next »