Skip to content

Commit ee9565c

Browse files
bp1222nikic
authored andcommitted
Update spec for by-ref list RFC
1 parent 9d99cf0 commit ee9565c

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

spec/10-expressions.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,7 @@ keyed-list-expression-list:
28522852
28532853
list-or-variable:
28542854
list-intrinsic
2855-
variable
2855+
'&'? variable
28562856
-->
28572857

28582858
<pre>
@@ -2874,7 +2874,7 @@ list-or-variable:
28742874

28752875
<i id="grammar-list-or-variable">list-or-variable:</i>
28762876
<i><a href="#grammar-list-intrinsic">list-intrinsic</a></i>
2877-
<i><a href="#grammar-variable">variable</a></i>
2877+
&amp;<sub>opt</sub> <i><a href="#grammar-variable">variable</a></i>
28782878
</pre>
28792879

28802880
**Constraints**
@@ -2892,7 +2892,8 @@ At least one of the elements of the *list-expression-list* must be non-empty.
28922892
**Semantics**
28932893

28942894
This intrinsic assigns one or more elements of the source array to the
2895-
target variables. On success, it returns a copy of the source array. If the
2895+
target variables. Target variables may be assigned by reference.
2896+
On success, it will return a copy of the source array. If the
28962897
source array is not an array or object implementing `ArrayAccess` no
28972898
assignments are performed and the return value is `NULL`.
28982899

@@ -2942,6 +2943,12 @@ list($arr[1], $arr[0]) = [0, 1];
29422943
list($arr2[], $arr2[]) = [0, 1];
29432944
// $arr2 is [0, 1]
29442945

2946+
$a = [1, 2];
2947+
list(&$one, $two) = $a;
2948+
// $a[0] is 1, $a[1] is 2
2949+
$one++;
2950+
// $a[0] is 2, $a[1] is 2
2951+
29452952
list("one" => $one, "two" => $two) = ["one" => 1, "two" => 2];
29462953
// $one is 1, $two is 2
29472954
list(
@@ -2952,6 +2959,13 @@ list(
29522959
"two" => 2,
29532960
];
29542961
// $one is 1, $two is 2
2962+
2963+
$a = ['one' => 1, 'two' => 2];
2964+
list('one' => &$one, 'two' => $two) = $a;
2965+
// $a['one'] is 1, $a['two'] is 2
2966+
$one++;
2967+
// $a['one'] is 2, $a['two'] is 2
2968+
29552969
list(list("x" => $x1, "y" => $y1), list("x" => $x2, "y" => $y2)) = [
29562970
["x" => 1, "y" => 2],
29572971
["x" => 3, "y" => 4]

spec/19-grammar.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ The grammar notation is described in [Grammars section](09-lexical-structure.md#
657657

658658
<i id="grammar-list-or-variable">list-or-variable:</i>
659659
<i><a href="#grammar-list-intrinsic">list-intrinsic</a></i>
660-
<i><a href="#grammar-variable">variable</a></i>
660+
&amp;<sub>opt</sub> <i><a href="#grammar-variable">variable</a></i>
661661

662662
<i id="grammar-byref-assignment-expression">byref-assignment-expression:</i>
663663
<i><a href="#grammar-variable">variable</a></i> = &amp; <i><a href="#grammar-variable">variable</a></i>

0 commit comments

Comments
 (0)