RE: [PHP] RE: create object from variable class.
| From: | Martin Towell | Date: | Wed, 24 Jul 2002 23:41:33 +0000 |
| Subject: | RE: [PHP] RE: create object from variable class. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-109381@lists.php.net to get a copy of this message | ||
This should work
$object = new $classname;
Martin
-----Original Message-----
From: Michiel ten Hagen [mailto:mtenhagen@virtuosys.nl]
Sent: Wednesday, July 24, 2002 11:17 PM
To: 'Mathieu Dumoulin'
Cc: php-general@lists.php.net
Subject: [PHP] RE: create object from variable class.
Thx for quick reply,
If I use the following:
$object = new {classname};
I get this a parse error:
Parse error: parse error, expecting
T_STRING' or T_VARIABLE'
or `'$'' in
/home/sites/projects.virtuosys.nl/web/cm/includes/class_crm.inc.php on
line 29
From that I conclude that with this method its not possible to create an
object from a variable class name
Michiel ten Hagen
mtenhagen@virtuosys.nl
06-54673863
-----Oorspronkelijk bericht-----
Van: Mathieu Dumoulin [mailto:mdumoulin@groupimage.com]
Verzonden: Wednesday, July 24, 2002 3:11 PM
Aan: mtenhagen@virtuosys.nl
Onderwerp: Re: create object from variable class.
Simple, you made an error here
You are telling the new operator to look into a variable to get the
classname, to specify the class name as a string do this:
$object = new {$classname};
InsaneCoder
Ps: I never tried this, but I think it is actually going to work, you
got nthing to lose anyway I guess, takes two seconds to try.
"Karel De Groot" <mtenhagen@virtuosys.nl> wrote in message
news:<20020724130121.64455.qmail@pb1.pair.com>...
> Is it possible to create an object from a clas which name is in a
> variable.
>
> Example: (doesn't work)
> $object = new ${$classname};
>
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php