Re: [PHP-DEV] unable to create class from constant

2005-09-19 Thread Marcus Boerger
Hello Jason, new doesn't expect a string which a constant in fact is. It expects a class name. Thus the class name cannot be constified. You'd need to use reflection for that: $r = new ReflectionClass($name); $o = $r->newInstance(); best regards marcus Monday, September 19, 2005, 6:58:31 PM, y

Re: [PHP-DEV] unable to create class from constant

2005-09-19 Thread Jason Sweat
On 9/19/05, Xuefer <[EMAIL PROTECTED]> wrote: > wrong list. :) My question was not "how do I work around this?". I included that in my original post. My question was "why is it like this?" which I thought was more germane to the internals list. An unquoted string would have to first be thought

Re: [PHP-DEV] unable to create class from constant

2005-09-19 Thread Xuefer
can u tell me why php -r 'function myfunc(){} define("X", "myfunc"); X(); ' Fatal error: Call to undefined function: x() in Command line code on line 1 but not calling myfunc? wrong list. :) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.p

Re: [PHP-DEV] unable to create class from constant

2005-09-19 Thread Sean Coates
> But I was wondering if anyone could enlighten me as to why php would > be upset interpreting the constant as the class name. Thanks. class Foo { function get_name() { return 'Foo'; } } class Bar { function get_name() { return 'Bar'; } } define('Foo', 'Bar'); $C = new Foo(); echo $C->get_

[PHP-DEV] unable to create class from constant

2005-09-19 Thread Jason Sweat
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. C