Re: 回复: [PHP-DEV] [RFC] Proposal nam espace importing with from syntax
| From: | Stas Malyshev | Date: | Wed, 25 Jul 2012 05:22:51 +0000 |
| Subject: | Re: 回复: [PHP-DEV] [RFC] Proposal nam espace importing with from syntax | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61735@lists.php.net to get a copy of this message | ||
Hi!
> No, we can not import namespace directly for now :
Of course you can. You just missing on what namespace import means in
PHP, it's not like Java (though a bit like Python).
> <?php
> namespace A {
> class B {}
> }
>
> namespace {
> use A;
>
> var_dump(new B());
> }
use A is a no-op, just as the warnings tell you. You can just write A\B.
It's only 2 characters more. If your A is longer, then you can alias it
to something shorter.
> and if we need alias we could:
> <?php
> // reduce
> use GlobalNamespace\SubSpace\ThirdSpace\Class1;
> use GlobalNamespace\SubSpace\ThirdSpace\Class2 as Alias2;
> use GlobalNamespace\SubSpace\ThirdSpace\ForthSpace\Class3 as Alias3;
You could just do
use GlobalNamespace\SubSpace\ThirdSpace as Spc;
$a = new Spc\Class1();
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227