Re: AW: [PHP-DEV] Namespace resolution
| From: | David Zülke | Date: | Tue, 11 Dec 2007 09:01:34 +0000 |
| Subject: | Re: AW: [PHP-DEV] Namespace resolution | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33919@lists.php.net to get a copy of this message | ||
The problem I see with that is that if I have an application that uses a 3rd-party library which does not use namespaces, I need to use ::LibClass everywhere. Until they switch to namespaces - then I need to touch hundreds and thousands lines of code. If LibClass were looked up in the global namespace, too, I could simply add the appropriate import statements at the top of each file.
Anyways, the process you described seems flawed in another fashion: It looks up a class in the namespace first, then an internal php class, then it tries an autoload. That does not make sense. Lets say I run some code as you described, and there is a class C(), but it's not been autoloaded yet. The internal class C is used. Then, later, the autoloading of A::B::C() is somehow forced. Now, if the same code runs again, a different class is used. That sounds like nonsense.
David
Am 11.12.2007 um 08:31 schrieb Matthias Pigulla:
-----Ursprüngliche Nachricht----- Von: Sam Barrow [mailto:sam@sambarrow.com] Gesendet: Montag, 10. Dezember 2007 22:48 An: internals@lists.php.net Betreff: [PHP-DEV] Namespace resolution Ok, it's supposed to be this way right? If i define a custom class in the global namespace called "myClass" and I'm in another namespace, I can only access it using ::myClass, not just myClass (without the colons)? Seems to me that it should check the local namespace and then the global, but it only checks the globl if i specifically tell it to with the preceding "::".From http://www.php.net/manual/en/language.namespaces.rules.php:-- Inside namespace (say A::B), calls to unqualified class names are resolved at run-time. Here is how a call to new C() is resolved: 1. It looks for a class from the current namespace : A::B::C(). 2. It tries to find and call the internal class C(). 3. It attemts to autoload A::B::C(). C(). To reference a user defined class in the global namespace, new ::C() has to be used. -- Which is exactly what you observed. -mp. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php