From e6ffa80d976b46c2dadcb55189fec6827de5df3f Mon Sep 17 00:00:00 2001 From: David Walker Date: Fri, 30 Dec 2016 20:20:48 -0700 Subject: [PATCH 1/2] Update spec for RFC --- spec/10-expressions.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/spec/10-expressions.md b/spec/10-expressions.md index 0fab9b33..24aa0136 100644 --- a/spec/10-expressions.md +++ b/spec/10-expressions.md @@ -2930,7 +2930,9 @@ At least one of the elements of the *list-expression-list* must be non-empty. **Semantics** This intrinsic assigns one or more elements of the source array to the -target variables. On success, it returns a copy of the source array. If the +target variables. On success, the target variable will be assigned to the +corresponding value in the source array. This can either be a reference +or a copy of the value depening if `&` preceeds the variable. If the source array is not an array or object implementing `ArrayAccess` no assignments are performed and the return value is `NULL`. @@ -2980,6 +2982,12 @@ list($arr[1], $arr[0]) = [0, 1]; list($arr2[], $arr2[]) = [0, 1]; // $arr2 is [0, 1] +$a = [1, 2]; +list(&$one, $two) = $a; + // $a[0] is 1, $a[1] is 2 +$one++; + // $a[0] is 2, $a[1] is 2 + list("one" => $one, "two" => $two) = ["one" => 1, "two" => 2]; // $one is 1, $two is 2 list( @@ -2990,6 +2998,13 @@ list( "two" => 2, ]; // $one is 1, $two is 2 + +$a = ['one' => 1, 'two' => 2]; +list('one' => &$one, 'two' => $two) = $a; + // $a['one'] is 1, $a['two'] is 2 +$one++; + // $a['one'] is 2, $a['two'] is 2 + list(list("x" => $x1, "y" => $y1), list("x" => $x2, "y" => $y2)) = [ ["x" => 1, "y" => 2], ["x" => 3, "y" => 4] From af257c542e982c5dfa1b60755d40ea7230f663d3 Mon Sep 17 00:00:00 2001 From: David Walker Date: Wed, 29 Aug 2018 10:52:41 -0600 Subject: [PATCH 2/2] Fix wording to re-add list() return value --- spec/10-expressions.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/10-expressions.md b/spec/10-expressions.md index 24aa0136..5d3ed2a4 100644 --- a/spec/10-expressions.md +++ b/spec/10-expressions.md @@ -2930,9 +2930,8 @@ At least one of the elements of the *list-expression-list* must be non-empty. **Semantics** This intrinsic assigns one or more elements of the source array to the -target variables. On success, the target variable will be assigned to the -corresponding value in the source array. This can either be a reference -or a copy of the value depening if `&` preceeds the variable. If the +target variables. Target variables may be assigned by reference. +On success, it will return a copy of the source array. If the source array is not an array or object implementing `ArrayAccess` no assignments are performed and the return value is `NULL`.