Hi Denis,
I understand what you are trying to do, unfortunely get_class(self) will not
work if self is an extended class (as Zend_Db tables are), the only
workaround (until 5.3 is out where will be possible to do this) is to create
a method, this is how I do it:
create an interface
interface My_Interface
{
public static function init();
}
then create your class
class My_Class extends Zend_Db_Table implements My_Interface
{
...
public static function init()
{
return new self;
}
}
then, when you need the class you must use $myClass::init() instead of new
$myclass
Hope it helps,
Aldemar
----- Original Message -----
From: "Denis Fohl" <[EMAIL PROTECTED]>
To: "Vincent" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Thursday, April 24, 2008 11:04 AM
Subject: Re: [fw-general] instantiate an object with a variable name for the
class
Thank you for your response Vincent,
for now, i have no other solution than instantiate the object before
calling my constructor and pass the Zend_Db_Table objects to it instead of
passing strings with their names... but it's not exactly what i wanted to
do.
cheers
Vincent a écrit :
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
--
Denis Fohl
--------------
df-info
06 84 38 21 99