unable to create class from constant
| From: | Jason Sweat | Date: | Mon, 19 Sep 2005 15:18:10 +0000 |
| Subject: | unable to create class from constant | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-19076@lists.php.net to get a copy of this message | ||
I ran across this today and it surprised me:
$ php -r 'define("X", "stdClass"); $x = new X; var_dump($x);';
Fatal error: Cannot instantiate non-existent class: x in Command line
code on line 1
I tested on php 4.4.0, 4.3.8 and 5.0.3, with the result that all
versions exhibit the same behavior.
Clearly there is an easy work around:
$ php -r 'define("X", "stdClass"); $y = X; $x = new $y;
var_dump($x);'
object(stdClass)(0) {
}
But I was wondering if anyone could enlighten me as to why php would
be upset interpreting the constant as the class name. Thanks.
Regards,
Jason
http://blog.casey-sweat.us/