Re: Instantiating class, classname in constant

From: Date: Mon, 30 Aug 2004 14:06:25 +0000
Subject: Re: Instantiating class, classname in constant
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-195163@lists.php.net to get a copy of this message
Wouter Van Vliet wrote:
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 -- Always consider all options before deciding which object to talk to Have you tried using this:
$bar = new constant("Foo::Bar")(); I have no idea if it'll work (it probably won't, but hey, why not give it a shot?) -- Daniel Schierbeck

« previous php.general (#195163) next »