> -----Ursprüngliche Nachricht-----
> Von: are.you.winn...@gmail.com [mailto:are.you.winn...@gmail.com] Im Auftrag 
> von Chris Wright
> Gesendet: Donnerstag, 13. November 2014 13:13
> An: Johannes Schlüter
> Cc: Robert Stoll; Adam Harvey; PHP Internals
> Betreff: Re: AW: [PHP-DEV] forbid use declaration outside of a namespace in 
> PHP 7
> 
> On 13 November 2014 11:29, Johannes Schlüter <johan...@schlueters.de> wrote:
> 
> > On Wed, 2014-11-12 at 22:27 +0100, Robert Stoll wrote:
> >
> > > 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.
> > > I am talking about the two following scenarios:
> > >
> > > use \Exception;
> > > namespace test;
> > >
> > > $e = new Exception(); //would fails because test\Exception is
> > > unknown ->
> > use was defined outside the namespace
> > >
> > >
> > > Or
> > > namespace a{
> > > }
> > >
> > > use some\UseDeclaration\which\is\outside\of\AnyNamespace as Useless;
> > > //
> > sorry for begin biased ^^
> > >
> > > namespace test{
> > > }
> >
> > If I get it rigth this might break code by people who, for whatever
> > reason, combine multiple PHP files into a single one. (cat *.php >
> > full.php && php full.php)
> >
> >
> This would only break if the individual files were already invalid. Files 
> with namespace Name; style ns declarations couldn't
> be joined together in this way anyway, and files using namespace Name { ... } 
> style declarations with use imports outside
> the block would be invalid on their own, concatenating them wouldn't break 
> (or fix) this situation. Unless I missed
> something?

[Robert Stoll] 
I share Chris' statement. Combining multiple files would only work if they all 
use namespace blocks or if they do not use any namespaces at all (and thus are 
implicitly in the default namespace).

> 
> I must say actually that while I think a use declaration outside a 
> block-style namespace should be invalid, I'm about 50/50 on
> whether something like this should be invalid:
> 
> <?php
> 
> use \Foo;
> namespace Bar;
> 
> The current behaviour is certainly wrong, but in this case it might be good 
> to treat it as if the use declaration was after the
> ns declaration, rather than making it invalid (I haven't looked at how easy 
> this would be to accomplish, though).
> 

[Robert Stoll] 
I think it would be wrong to start to do such auto-fixes. Syntax which is wrong 
should emit a fatal error IMO (assuming we would disallow use-statement outside 
of a namespace). In this case the user has to move the statement down a few 
lines and it works again. Better than auto-fixing which might introduce 
unintended bugs.

> 
> johannes
> >
> >
> > --
> > PHP Internals - PHP Runtime Development Mailing List To unsubscribe,
> > visit: http://www.php.net/unsub.php
> >
> >


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to