AW: [PHP-DEV] Namespace resolution
| From: | Matthias Pigulla | Date: | Tue, 11 Dec 2007 07:31:56 +0000 |
| Subject: | AW: [PHP-DEV] Namespace resolution | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-33918@lists.php.net to get a copy of this message | ||
> -----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.