Re: AW: AW: [PHP-DEV] forbid use declaration outside of a namespace in PHP 7

From: Date: Thu, 13 Nov 2014 12:56:17 +0000
Subject: Re: AW: AW: [PHP-DEV] forbid use declaration outside of a namespace in PHP 7
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-78895@lists.php.net to get a copy of this message
Robert Stoll wrote on 13/11/2014 12:30:
-----Ursprüngliche Nachricht-----
Von: Rowan Collins [mailto:rowan.collins@gmail.com] Gesendet: Donnerstag, 13. November 2014 11:57 An:internals@lists.php.net Betreff: Re: AW: [PHP-DEV] forbid use declaration outside of a namespace in PHP 7 Robert Stoll wrote on 12/11/2014 21:27:
That's still perfectly fine because in your code the use statement is not outside of a namespace, it is implicitly in the
default namespace. Surely if that's true of Adam's example, it's true of yours as well? [Robert Stoll] The difference is that I have specified a namespace and thus code outside of that namespace is no longer implicitly in the default namespace.
Ah, OK, on further experimenting, and closer reading of the documentation, I see that you are right. For anyone else wondering, the key quotes from the manual are: - "A file containing a namespace must declare the namespace at the top of the file before any other code - with one exception: the declare <http://php.net/manual/en/control-structures.declare.php> keyword." - "No PHP code may exist outside of the namespace brackets except for an opening declare statement." So as soon as the keyword "namespace" appears somewhere in the file, there is no longer any implicit global non-namespaced code. As such, it seems to me that allowing a "use" statement is simply a bug - no other code is allowed in that position, and the only documented exception to that rule is declare(). Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#78895) next »