php / php-langspec

PHP Language Specification
http://www.php.net
Other
2.3k stars 271 forks source link

Specify when imported names become available #238

Open mattacosta opened 5 years ago

mattacosta commented 5 years ago

The specification currently states that use declarations bring a name into a scope, but that's not exactly true, as imports are not available prior to the use declaration.

namespace A {
    class C {}
}
namespace B {
    // Same scope, 'A\C' should be available right?!
    $c = new C();
    use A\C;
}

Without this restriction, an engine could theoretically make an initial pass to import names from all use declarations, and therefore prevent a name resolution error from occurring.

18-namespaces.md

A namespace-use-declaration imports — that is, makes available — one or more names into a scope, optionally giving them each an alias.