Instantiating class, classname in constant
| From: | Wouter van Vliet | Date: | Mon, 30 Aug 2004 12:43:03 +0000 |
| Subject: | Instantiating class, classname in constant | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-195159@lists.php.net to get a copy of this message | ||
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