> -----Ursprüngliche Nachricht-----
> Von: Rowan Collins [mailto:[email protected]]
> Gesendet: Donnerstag, 13. November 2014 11:57
> An: [email protected]
> 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.
> > namespace a{
> > }
> >
> > use some\UseDeclaration\which\is\outside\of\AnyNamespace as Useless;
> > // sorry for begin biased ^^
> >
> > namespace test{
> > }
>
> This scenario looks identical to Adam's to me, unless you propose to look at
> the entirety of the file to detect if there is
> something other than a use statement in the default namespace.
[Robert Stoll]
Same applies here, my use statement is outside of a namespace Adam's isn't.
> For that matter, what about this:
>
> use GuzzleHttp\Client;
>
> include __DIR__.'/vendor/autoload.php';
>
> $client = new Client;
> // $client is a GuzzleHttp\Client object
>
> namespace Foo;
> $client = new Client;
> // $client is a Foo\Client object
>
> Certainly this code is not *sensible*, but it does have a meaningful
> behaviour, which derives directly from the previous
> examples and documented uses of the namespace keyword. I'm not sure how you'd
> distinguish between the various
> combinations here.
>
> Regards,
> --
> Rowan Collins
> [IMSoP]
>
[Robert Stoll]
I haven't tested it I am pretty sure this script would fail since $client = new
Client is outside of a namespace - an error message something like "namespace
must be the first statement" would show up.
If I rewrite your code to the following:
namespace{
use GuzzleHttp\Client;
include __DIR__.'/vendor/autoload.php';
$client = new Client;
// $client is a GuzzleHttp\Client object
namespace Foo{
$client = new Client;
// $client is a Foo\Client object
}
Then it would make sense (use statement is inside a namespace).
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php