php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #68136 list intrinsic starting with the right-most parameter
Submitted: 2014-10-02 20:39 UTC Modified: 2016-11-11 21:53 UTC
From: rstoll at tutteli dot ch Assigned: nikic (profile)
Status: Closed Package: PHP Language Specification
PHP Version: 5.6.0 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
49 - 40 = ?
Subscribe to this entry?

 
 [2014-10-02 20:39 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-22 19:14 UTC] 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-11-22 19:15 UTC] 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);
 [2016-11-11 21:53 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-11-11 21:53 UTC] nikic@php.net
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.".
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jan 21 19:01:27 2021 UTC