rfc:short_list_syntax

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:short_list_syntax [2016/04/05 14:02] – ] ajfrfc:short_list_syntax [2016/05/20 00:03] – Implemented ajf
Line 1: Line 1:
 ====== PHP RFC: Square bracket syntax for array destructuring assignment ====== ====== PHP RFC: Square bracket syntax for array destructuring assignment ======
   * Version: 1.0   * Version: 1.0
-  * Date: 2016-04-03+  * Date: 2016-04-07
   * Authors: Andrea Faulds <ajf@ajf.me>, Bob Weinand <bwoebi@php.net>   * Authors: Andrea Faulds <ajf@ajf.me>, Bob Weinand <bwoebi@php.net>
-  * Status: Draft+  * Status: Implemented (PHP 7.1)
   * First Published at: http://wiki.php.net/rfc/short_list_syntax   * First Published at: http://wiki.php.net/rfc/short_list_syntax
  
Line 72: Line 72:
 This syntax is more concise, and like the <php>[]</php> alternative to <php>array()</php>, this new syntax does not resemble a function call. This syntax is more concise, and like the <php>[]</php> alternative to <php>array()</php>, this new syntax does not resemble a function call.
  
-Importantly, this syntax for destructuring an array means there is now symmetry between array construction and destructuring, which should make the purpose more obvious:+Importantly, this syntax for destructuring an array means there is now symmetry between array construction and destructuring, which should make it clearer what the function of the syntax is:
  
 <code php> <code php>
 <?php <?php
  
-// These two statements are equivalent:+// The two lines in each of the following pairs are equivalent to each other 
 list($a, $b, $c) = array(1, 2, 3); list($a, $b, $c) = array(1, 2, 3);
 [$a, $b, $c] = [1, 2, 3]; [$a, $b, $c] = [1, 2, 3];
  
-// These two statements are also equivalent: 
 list("a" => $a, "b" => $b, "c" => $c) = array("a" => 1, "b" => 2, "c" => 3); list("a" => $a, "b" => $b, "c" => $c) = array("a" => 1, "b" => 2, "c" => 3);
 ["a" => $a, "b" => $b, "c" => $c] = ["a" => 1, "b" => 2, "c" => 3]; ["a" => $a, "b" => $b, "c" => $c] = ["a" => 1, "b" => 2, "c" => 3];
 +
 +list($a, $b) = array($b, $a);
 +[$a, $b] = [$b, $a];
 </code> </code>
  
Line 98: Line 101:
 ===== Details ===== ===== Details =====
  
-The <php>list()</php> syntax is not only permitted on the left-hand side of an assignment operation, but also as variable in a <php>foreach</php> loop. The new <php>[]</php> syntax for destructuring would work the same here:+The <php>list()</php> syntax is not only permitted on the left-hand side of an assignment operation, but also as variable in a <php>foreach</php> loop. The new <php>[]</php> syntax for destructuring would likewise be permitted here:
  
 <code php> <code php>
Line 118: Line 121:
 // This is also not allowed: // This is also not allowed:
 [list($a, $b), list($c, $d)] = [[1, 2], [3, 4]]; [list($a, $b), list($c, $d)] = [[1, 2], [3, 4]];
 +
 +// This, however, is allowed:
 +[[$a, $b], [$c, $d]] = [[1, 2], [3, 4]];
 </code> </code>
 +
 +Aside from this restriction, assignment with <php>[]</php> on the left-hand side behaves identically to <php>list()</php> in all respects.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
Line 136: Line 144:
 ===== Open Issues ===== ===== Open Issues =====
  
-Currently, the patch permits nesting the <php>[]</php> syntax form within <php>list()</php>. This will need to be fixed.+None.
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
  
-The existing <php>list()</php> syntax will not be removednor deprecated, as a result of this RFC.+This RFC does not remove nor deprecate the existing <php>list()</php> syntax, and it continues to function identically.
  
 ===== Future Scope ===== ===== Future Scope =====
Line 146: Line 154:
 We may wish to introduce destructuring assignment syntax for objects in future. We may wish to introduce destructuring assignment syntax for objects in future.
  
-===== Proposed Voting Choices =====+===== Vote =====
  
 Because this proposal affects the language syntax (and also therefore the specification), it is a language change and requires at least a 2/3 majority to be accepted when put to a vote. Because this proposal affects the language syntax (and also therefore the specification), it is a language change and requires at least a 2/3 majority to be accepted when put to a vote.
  
 The vote will be a simple Yes/No vote on whether or not to accept the RFC for PHP 7.1 and merge the patch into master. The vote will be a simple Yes/No vote on whether or not to accept the RFC for PHP 7.1 and merge the patch into master.
 +
 +Voting started on 2016-04-27 and ended on 2016-05-08.
 +
 +<doodle title="Accept the RFC Square bracket syntax for array destructuring assignment for PHP 7.1?" auth="ajf" voteType="single" closed="true">
 +   * Yes
 +   * No
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
  
-TODO php-src+There is a pull request, with tests, for the PHP interpreter (''php-src'') here: https://github.com/php/php-src/pull/1849
  
-TODO php-langspec+There is not yet a patch or pull request for the language specification (''php-langspec'').
  
 ===== Implementation ===== ===== Implementation =====
 +Merged into master for PHP 7.1: http://git.php.net/?p=php-src.git;a=commitdiff;h=4f077aee836ad7d8335cf62629a8364bdf939db9
 +
 +Not yet in the language specification.
 +
 After the project is implemented, this section should contain  After the project is implemented, this section should contain 
-  - the version(s) it was merged to 
-  - a link to the git commit(s) 
   - a link to the PHP manual entry for the feature   - a link to the PHP manual entry for the feature
  
rfc/short_list_syntax.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1