Re: Instantiating class, classname in constant

From: Date: Mon, 30 Aug 2004 14:07:45 +0000
Subject: Re: Instantiating class, classname in constant
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-195162@lists.php.net to get a copy of this message
I don't know. Ask them ! Fred. Wouter van Vliet wrote:
Quoting Frédéric Hardy <f.hardy@hexanet.fr>:
Hi Fella's, Some of you might or might not remember me. I've been here before and I am
here
again. Hoping to stick around, ask, wonder and help a lot. So much for a starter. Now, aren't all of you as excited about php5 as I am? What a great change
to the
object model. Especially, .. well, basically all modifications are as good
as
all of the others. There's only one thing I can't seem to get working - not after googling, trying, searching, reading. Not even after just trying everything I thought to be reasonable. It's the following: <?php class Foo {
 const Bar       = 'Foo_Bar';
const Chocolate = 'Foo_Chocolate';
 const Target    = 'Foo Target';
} $bar = new Foo::Bar(); ?> even though <?php $bar = Foo::Bar; $bar = new $bar(); ?> does instantiate an object of class Foo_Bar; After all this time I've given up on it, please ow please just tell me why
it's
not working. Same thing, btw, doesn't work for $obj = new __CLASS__(); or
any
object instantiation where the classname should come from something else
then a
regular, scalar variable. Any discussion on the item would be great, Wouter
Hello - It is not possible to do that. PHP new keyword does not support constant in argument, only string or variable :-(. Fred.
Thought so, .. but what I am interested in is why the php team (or zend) decided to not make that possible. It would result in so much better support for "packages" of modules. Especially when mixed up with some cool __autoload() tricks.
-- =================================================================== Frederic HARDY Email: fch@hexanet.fr HEXANET SARL URL: http://www.hexanet.fr/ ZAC Les Charmilles Tel: +33 (0)3 26 79 30 05 3, allée Thierry Sabine Direct: +33 (0)3 26 61 77 84 BP 202 - 51686 REIMS CEDEX 2 FRANCE ===================================================================

« previous php.general (#195162) next »