Re: [STANDARDS] Use declaration outside of namespace
[email protected] (Chris Wright)
| Newsgroups | php.standards |
|---|---|
| Message-ID | <CAGAGxbaOfhX9ZJgtrGpmn0hQjANgCLZteo45rP1rk7bRSPHUrQ@mail.gmail.com> |
On 29 October 2014 09:12, Robert Stoll <[email protected]> wrote: > Heya, > > I always found it very ugly that it is possible to define a use outside of > a namespace. Consider the following: > > use foo\Bar; > namespace test; > new Bar(); //error, test\Barnot found > > I do not see why we should actually support this behaviour in the > specification of PHP. I do not see it as a bug in the > current PHP implementation but I think we should consider to remove it in > PHP 7. Although, it is not a bug, the use > declaration is simply ignored as far as I can tell, but I suppose it > confuses the user. Nevertheless, even if we declare > it as a "feature" I think it should not be a "feature" of the > specification. > > Thoughts? > > TL;DR if you revise wording of the suggested change from "outside of a namespace" to "before a namespace declaration", +1 Removing the ability "use" things outside a namespace is not acceptable to me. I have often written quick scripts that use things from many namespaces but don't belong in a specific namespace, and in those cases I usually don't declare a namespace (it's also worth noting that you're never "outside a namespace", you're just in the root namespace by default). That said, placing the "use" statements before the namespace declaration doesn't make a whole bunch of sense and should probably be explicitly disallowed. The fact that it works in php-src at the moment is arguably an oversight, if you try to actually *do* anything before the namespace declaration you even get an error stating that it "has to be the very first statement in the script" - so this case should probably be disallowed. Thanks, Chris > Cheers, > Robert > > > -- > PHP Naming Standardization Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >