Re: 5.3 and reflection

From: Date: Tue, 13 May 2008 21:59:40 +0000
Subject: Re: 5.3 and reflection
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-37637@lists.php.net to get a copy of this message
Hi!
To continue your example, if I tried to do this: $reflect = new ReflectionClass("Baz"); it would not work, regardless of the namespace of the file that statement appears in. I must instead do this: $reflect = new ReflectionClass("Foo::Bar::Baz");
Right. You can use __NAMESPACE__ compile-time constant to save yourself some typing and maintenance if you are doing it inside namespace declaration. So it'd be: $reflect = new ReflectionClass(__NAMESPACE__."::Baz");
Furthermore, there will never be a way to reflect a namespace, since the concept of namespacing is essentially lost by the time the reflection code would be executed. Is this accurate?
Yes. You can of course get class name and split it by :: and use the parts as you wish, but there's no such separate entity as "namespace" containing classes in the engine, so you can ask only "what class names begin with Foo::Bar::". We could make reflection method that does just that - i.e. lists classes beginning with certain prefix - but we didn't see a need for it yet. If there would be some user demand for it, it might be added later. -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

« previous php.internals (#37637) next »