I am on PHP 5.2.5 and for me it works to use:

$fubar = new $class($params ...);

Cheers,
Holger




-----Original Message-----
From: Pete Spicer [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 24, 2008 6:09 PM
To: [email protected]
Subject: Re: [fw-general] instantiate an object with a variable name for the 
class

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 

Reply via email to