Doc #68136 [Opn->Csd]: list intrinsic starting with the right-most parameter
| From: | nikic@php.net | Date: | Fri, 11 Nov 2016 21:53:44 +0000 |
| Subject: | Doc #68136 [Opn->Csd]: list intrinsic starting with the right-most parameter | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-14094@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68136&edit=1
ID: 68136
Updated by: nikic@php.net
Reported by: rstoll at tutteli dot ch
Summary: list intrinsic starting with the right-most
parameter
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: PHP Language Specification
PHP Version: 5.6.0
-Assigned To:
+Assigned To: nikic
Block user comment: N
Private report: N
New Comment:
As of PHP 7.0 list assignment occur left-to-right. The spec covers this in the sentence "The
assignments must occur in this order.".
Previous Comments:
------------------------------------------------------------------------
[2014-11-22 19:15:58] salathe@php.net
Or when providing explicit indices:
list($arr['a'], $arr['b'], $arr['c']) = array(0, 100, 67);
Gives:
array('c' => 67, 'b' => 100, 'a' => 0);
------------------------------------------------------------------------
[2014-11-22 19:14:03] salathe@php.net
The quoted warning describes the result for the following example:
list($arr[], $arr[], $arr[]) = array(0, 100, 67);
All currently released versions have the resulting $arr like so:
array(67, 100, 0);
Do note, that this has been changed in php-src's master branch.
------------------------------------------------------------------------
[2014-10-02 20:39:26] rstoll at tutteli dot ch
Description:
------------
see:
https://github.com/php/php-langspec/blob/master/spec/10-expressions.md#list
and:
php.net/manual/en/function.list.php
The manual states:
Warning
list() assigns the values starting with the right-most parameter. If you are using plain variables,
you don't have to worry about this. But if you are using arrays with indices you usually expect
the order of the indices in the array the same you wrote in the list() from left to right; which it
isn't. It's assigned in the reverse order.
Right now I cannot really grasp what this warning tries to explain but I can see that it is missing
in the spec.
Either the manual is wrong or the spec
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68136&edit=1