com php-langspec: Update spec for by-ref list RFC: spec/10-expressions.md spec/19-grammar.md

From: Date: Fri, 15 Mar 2019 09:30:11 +0000
Subject: com php-langspec: Update spec for by-ref list RFC: spec/10-expressions.md spec/19-grammar.md
Groups: php.standards.cvs 
Request: Send a blank email to standards--cvs+get-432@lists.php.net to get a copy of this message
Commit: ee9565cf6affd003280097f76cfa82f756e2305c Author: David Walker <dave@mudsite.com> Fri, 30 Dec 2016 20:20:48 -0700 Committer: Nikita Popov <nikita.ppv@gmail.com> Fri, 15 Mar 2019 10:30:11 +0100 Parents: 9d99cf029b84f40b99bdab0224c79dd89c09e41a Branches: master Link: http://git.php.net/?p=php-langspec.git;a=commitdiff;h=ee9565cf6affd003280097f76cfa82f756e2305c Log: Update spec for by-ref list RFC Changed paths: M spec/10-expressions.md M spec/19-grammar.md Diff: diff --git a/spec/10-expressions.md b/spec/10-expressions.md index 8c8af69..0e8fc92 100644 --- a/spec/10-expressions.md +++ b/spec/10-expressions.md @@ -2852,7 +2852,7 @@ keyed-list-expression-list: list-or-variable: list-intrinsic - variable + '&'? variable --> <pre> @@ -2874,7 +2874,7 @@ list-or-variable: <i id="grammar-list-or-variable">list-or-variable:</i> <i><a href="#grammar-list-intrinsic">list-intrinsic</a></i> - <i><a href="#grammar-variable">variable</a></i> + &amp;<sub>opt</sub> <i><a href="#grammar-variable">variable</a></i> </pre> **Constraints** @@ -2892,7 +2892,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, it returns a copy of the source array. 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. @@ -2942,6 +2943,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( @@ -2952,6 +2959,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] diff --git a/spec/19-grammar.md b/spec/19-grammar.md index 0cc4f68..3755b4b 100644 --- a/spec/19-grammar.md +++ b/spec/19-grammar.md @@ -657,7 +657,7 @@ The grammar notation is described in [Grammars section](09-lexical-structure..md# <i id="grammar-list-or-variable">list-or-variable:</i> <i><a href="#grammar-list-intrinsic">list-intrinsic</a></i> - <i><a href="#grammar-variable">variable</a></i> + &amp;<sub>opt</sub> <i><a href="#grammar-variable">variable</a></i> <i id="grammar-byref-assignment-expression">byref-assignment-expression:</i> <i><a href="#grammar-variable">variable</a></i> = &amp; <i><a href="#grammar-variable">variable</a></i>

« previous php.standards.cvs (#432) next »