For the record, brackets _should_ be specified when instantiating classes in such a manner. PHP supports omitting the brackets for any class that does not require constructor parameters. For code clarity, I think empty brackets should always be explicitly used.
Mike On Thu, 2008-24-04 at 17:08 +0100, Pete Spicer wrote: > Hello > It is possible to instantiate a class from a variable name - before PHP > 5.3 even. I've been doing this with 5.2 in a project I'm working on. > > I think the key thing is the syntax: > $table1 = new $originClass; // note no brackets > > Hopefully that'll help! > > Pete > > > > > > On 4/24/08, *Denis Fohl* <[EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>> wrote: > > > > Hi all, > > > > sorry i forgot the subject in my previous post : > > > > i'm trying to implement a class to manage manytomany relationships > > in backoffice, i'd like to standardize it for reusability. > > I would like to pass to the constructor of my class the name of > > the tables involved (destination table, origin table, intersection > > table) and that it instantiate correspondings Zend_Db_Table objects. > > > > So now is the question : how can i instantiate an object > > (Zend_Db_Table here) with a variable classname : > > > > function __construct ($originTable, $destinationTable) { > > > > $table1 = new $originTable(); > > ... > > > > } > > > > i can't find what i want on google (tried call_user_func but > > that's not it). > > > > > > This sounds similar to something I've been trying to do a while ago. > > After reading a *lot* about this, I found out this was not possible > > before PHP 5.3. I'm not sure exactly where I found that, but a good > > starting point would be the comments on http://nl3.php.net/get-class . > > > > Thanks. > > > > Denis. > > > > > > Best of luck, > > > > -- > > Vincent >
