rfc:namespace-importing-with-from
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:namespace-importing-with-from [2012/07/24 10:25] – created reeze | rfc:namespace-importing-with-from [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Request for Comments: Enhance Namespace Importing | + | ====== Request for Comments: Enhance Namespace |
* Version: 1.0 | * Version: 1.0 | ||
* Date: 2012-07-24 | * Date: 2012-07-24 | ||
- | * Author: Reeze Xia <reeze.xia@gmail.com> | + | * Author: Reeze Xia <reeze@php.net> |
* Status: Under Discussion | * Status: Under Discussion | ||
* First Published at: https:// | * First Published at: https:// | ||
Line 8: | Line 8: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | This RFC proposes adding a new <code php> | + | This RFC proposes adding a new syntax |
- | to help reduce deplication when importing class/ | + | This syntax is used to import multiple symbols |
+ | It will make namespace importing easier and reduce deplication. | ||
===== Use case ===== | ===== Use case ===== | ||
Line 17: | Line 18: | ||
<code php> | <code php> | ||
- | use Top\A\Long\Namespaced\ClassA; | + | <?php |
- | use Top\A\Long\Namespaced\ClassB; | + | use GlobalNamespace\SubSpace\ThirdSpace\Class1; |
- | use Top\A\Long\Namespaced\ClassC; | + | use GlobalNamespace\SubSpace\ThirdSpace\Class2; |
+ | use GlobalNamespace\SubSpace\ThirdSpace\ForthSpace\Class3; | ||
</ | </ | ||
Line 26: | Line 28: | ||
This RFC proposes a new syntax to allow developers reduce duplication as below: | This RFC proposes a new syntax to allow developers reduce duplication as below: | ||
<code php> | <code php> | ||
- | from Top\A\Long\Namespaced\NS | + | <?php |
+ | from GlobalNamespace\SubSpace\ThirdSace | ||
</ | </ | ||
- | It's considered to be an equivalent to the previous multiple use statements. | + | It will be an equivalent to the previous multiple use statements. |
This makes code less and easier to maintain. | This makes code less and easier to maintain. | ||
We could import by combine multiple use statement to a single line. | We could import by combine multiple use statement to a single line. | ||
<code php> | <code php> | ||
+ | <?php | ||
use Top\Namespaced\ClassA, | use Top\Namespaced\ClassA, | ||
</ | </ | ||
- | but it didn't reduce duplication | + | but it didn't reduce duplication |
===== Syntax explain ===== | ===== Syntax explain ===== | ||
Line 43: | Line 47: | ||
The syntax is '' | The syntax is '' | ||
- | In short this syntax enabled develpers to import several SYMBOLs from the same namespace once. | ||
- | topnamespace could be considered as a prefix to every follow use statement: | + | In short this syntax enable develpers import several symbols from the same namespace once. |
+ | |||
+ | 'topnamespace' | ||
<code php> | <code php> | ||
- | from Top\Namespaced use ClassA, ClassB, ClassC; | + | <?php |
- | //equals to | + | from Top\Namespaced use ClassA, ClassB, ClassC; // equals(expand) |
- | Top\Namespaced\ClassA; | + | |
- | Top\Namespaced\ClassB; | + | use Top\Namespaced\ClassA; |
- | Top\Namespaced\ClassB; | + | use Top\Namespaced\ClassB; |
+ | use Top\Namespaced\ClassB; | ||
- | // we can also import | + | // we can also import |
- | from \GloalNS\Company\Tools use \Tool1, use ToolCollection\NewTool as MyTool; | + | from \GlobalNS\Company\Tools use \Tool1, use SubCollection\NewTool as MyTool; |
</ | </ | ||
Line 62: | Line 68: | ||
==== Why '' | ==== Why '' | ||
+ | |||
It was inspired by Python, it use '' | It was inspired by Python, it use '' | ||
- | it's easy to understand what '' | + | it's easy to understand what '' |
since PHP use '' | since PHP use '' | ||
so '' | so '' | ||
- | ==== Can we use * to import? ==== | + | ==== Can we '' |
No ' | No ' | ||
- | |||
- | ==== Any BC break? ==== | ||
- | There should no BC break here. | ||
===== More examples ===== | ===== More examples ===== | ||
Line 97: | Line 101: | ||
* use A\B as B2; | * use A\B as B2; | ||
*/ | */ | ||
- | from A use B as B1, B as B2; | + | from A use B as B1, B as B2, C\X as X0; |
/* | /* | ||
Line 148: | Line 152: | ||
* 2012-07-24 Initially created by Reeze Xia | * 2012-07-24 Initially created by Reeze Xia | ||
- |
rfc/namespace-importing-with-from.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1