rfc:batch_use_declarations

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
rfc:batch_use_declarations [2015/01/29 22:51] – accept Danack's suggestions marciorfc:batch_use_declarations [2015/01/29 23:14] – change feature name to "group use declarations" marcio
Line 1: Line 1:
-====== PHP RFC: Batch Use Declarations ======+====== PHP RFC: Group Use Declarations ======
   * Date: 2015-01-28   * Date: 2015-01-28
   * Author: Márcio Almada, marcio.web2@gmail.com   * Author: Márcio Almada, marcio.web2@gmail.com
   * Status: Draft   * Status: Draft
-  * First Published at: http://wiki.php.net/rfc/batch_use_declarations+  * First Published at: http://wiki.php.net/rfc/group_use_declarations
   * Patch: https://github.com/php/php-src/pull/1005   * Patch: https://github.com/php/php-src/pull/1005
  
 ===== Introduction ===== ===== Introduction =====
-This RFC represents an attempt to improve current PHP namespace implementation by introducing the concept of **Batch Use Declarations**:+This RFC represents an attempt to improve current PHP namespace implementation by introducing the concept of **Group Use Declarations**:
  
 <code php> <code php>
-// Proposed batch use syntax:+// Proposed group use syntax:
  
 use FooLibrary\Bar\Baz\Biz { ClassA, ClassB, ClassC as Fizbo, ClassD }; use FooLibrary\Bar\Baz\Biz { ClassA, ClassB, ClassC as Fizbo, ClassD };
Line 23: Line 23:
  
 ===== Proposal ===== ===== Proposal =====
-Batch use declarations, also known as **grouped imports**, are just **syntax sugar** to cut verbosity when importing multiple entities from a common namespace. Using common PHP library examples, the following use declarations are equivalents:+Group use declarations, also known as **grouped imports**, are just **syntax sugar** to cut verbosity when importing multiple entities from a common namespace. Using common PHP library examples, the following use declarations are equivalents:
  
 <code php> <code php>
Line 32: Line 32:
 use Doctrine\Common\Collections\Expr\CompositeExpression; use Doctrine\Common\Collections\Expr\CompositeExpression;
  
-// Proposed batch use syntax:+// Proposed group use syntax:
  
 use Doctrine\Common\Collections\Expr { Comparison, Value, CompositeExpression }; use Doctrine\Common\Collections\Expr { Comparison, Value, CompositeExpression };
Line 52: Line 52:
 use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Question\ConfirmationQuestion;
  
-// Proposed batch use syntax:+// Proposed group use syntax:
  
 use Symfony\Component\Console { use Symfony\Component\Console {
Line 72: Line 72:
  
 === Non Mixed Use Declarations === === Non Mixed Use Declarations ===
-As expected, non mixed batch use declarations are supported:+As expected, non mixed group use declarations are supported:
  
 <code php> <code php>
Line 80: Line 80:
 use const foo\math\PI, foo\math\E, foo\math\GAMMA, foo\math\GOLDEN_RATIO; use const foo\math\PI, foo\math\E, foo\math\GAMMA, foo\math\GOLDEN_RATIO;
  
-// Proposed non mixed batch use syntax:+// Proposed non mixed group use syntax:
  
 use function foo\math { sin, cos, cosh }; use function foo\math { sin, cos, cosh };
Line 99: Line 99:
 use function foo\math\sin, foo\math\cos, foo\math\cosh; use function foo\math\sin, foo\math\cos, foo\math\cosh;
  
-// Proposed mixed batch use syntax:+// Proposed mixed group use syntax:
  
 use foo\math { Math, const PI, function sin, function cos, function cosh }; use foo\math { Math, const PI, function sin, function cos, function cosh };
Line 107: Line 107:
 ===== Justification ===== ===== Justification =====
  
-Batch use statements makes it easier to identify that multiple imported entities are from the same module. For the first example in this RFC, instead of having to read 'FooLibrary\Bar\Baz\Biz' four times to see that the namespace is the same for each entry, it is clear by the grouping syntax that the entries all come from the same namespace.+Group use statements makes it easier to identify that multiple imported entities are from the same module. For the first example in this RFC, instead of having to read 'FooLibrary\Bar\Baz\Biz' four times to see that the namespace is the same for each entry, it is clear by the grouping syntax that the entries all come from the same namespace.
  
-Also, batch use statements makes it easier to see in patch diffs that a dependency on a new module has been introduced. For instance, a patch that adds a new dependency on "Consolidation" namespace has been introduced:+Also, group use statements makes it easier to see in patch diffs that a dependency on a new module has been introduced. For instance, a patch that adds a new dependency on "Consolidation" namespace has been introduced:
  
 <code> <code>
Line 133: Line 133:
  
 ===== About The Syntax Choice ===== ===== About The Syntax Choice =====
-The syntax chosen is inline with the current trait adaptation syntax to make it look and feel similar to existing PHP standards.+The syntax chosen is inline with the current trait adaptation syntax to make it look and feel similar to existing PHP standards. Such design choice allows the feature to stay familiar and intuitive to most PHP user base.
  
-Such design choice allows the feature to stay familiar and intuitive to most PHP user base. +===== Optional: Nested Group Use Declarations =====
- +
-===== Optional: Nested Batch Use Declarations =====+
 **Nesting** would allow the following use case: **Nesting** would allow the following use case:
  
Line 163: Line 161:
  
 ===== Open Issues ===== ===== Open Issues =====
-  * Should nested batch use declarations be allowed?+  * Should nested group use declarations be allowed?
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
-Original namespace implementation is not affected by the addition of batch use declarations. Current syntax would still be valid.+Original namespace implementation is not affected by the addition of group use declarations. Current syntax would still be valid.
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
Line 174: Line 172:
 The implementation aims to be minimal and of easy maintenance. I created a PR so that the patch diff can be viewed easily: https://github.com/php/php-src/pull/1005 The implementation aims to be minimal and of easy maintenance. I created a PR so that the patch diff can be viewed easily: https://github.com/php/php-src/pull/1005
  
-The current initial implementation can be found on my PHP [[https://github.com/marcioAlmada/php-src/tree/batch-use|fork]]. You can also directly contribute to this RFC by sending a pull request to https://github.com/marcioAlmada/RFCs.+The current initial implementation can be found on my PHP [[https://github.com/marcioAlmada/php-src/tree/group-use|fork]]. You can also directly contribute to this RFC by sending a pull request to https://github.com/marcioAlmada/RFCs.
  
 ===== References ===== ===== References =====
-There is no found record related to batch use declarations on mailing lists.+There is no found record related to group use declarations on mailing lists.
  
 ==== Support in other languages ==== ==== Support in other languages ====
rfc/batch_use_declarations.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1