AW: [PHP-DEV] forbid use declaration outside of a namespace in PHP 7
| From: | Robert Stoll | Date: | Wed, 12 Nov 2014 21:27:29 +0000 |
| Subject: | AW: [PHP-DEV] forbid use declaration outside of a namespace in PHP 7 | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78889@lists.php.net to get a copy of this message | ||
> Sorry, I apparently missed this the first time. Would this mean that this sort of script (where
> we're using use statements
> without a
> namespace) would no longer work?
>
> <?php
> use GuzzleHttp\Client;
>
> include __DIR__.'/vendor/autoload.php';
>
> $client = new Client;
> // $client is a GuzzleHttp\Client object ?>
>
> Because that strikes me as an irritating and unnecessary BC break for people who are writing
> throwaway scripts (with no
> need to live in
> namespaces) that pull in namespaced libraries to me.
>
> Adam
>
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{
}
Cheers,
Robert