php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65221 Does not adequately explain nature of how list retrieves values from an array
Submitted: 2013-07-09 03:53 UTC Modified: 2016-06-25 16:10 UTC
From: lucas at threeamdesign dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: lucas at threeamdesign dot com
New email:
PHP Version: OS:

 

 [2013-07-09 03:53 UTC] lucas at threeamdesign dot com
Description:
------------
---
From manual page: http://www.php.net/function.list
---

The main description for the construct should specify that it only operates on numeric indices of an array (i.e. string keys are ignored) and expects them to be consecutive and starting at 0. It should also state that the order in which the indices were defined is irrelevant.

Test script:
---------------
This behaviour could be explained clearly, like so:

<?php
$foo = array(2 => 'a', 'foo' => 'b', 0 => 'c');
$foo[1] = 'd';
list($x, $y, $z) = $foo;
var_dump($foo, $x, $y, $z);
?>

produces the following result:

array(4) {
  [2]=>
  string(1) "a"
  ["foo"]=>
  string(1) "b"
  [0]=>
  string(1) "c"
  [1]=>
  string(1) "d"
}
string(1) "c"
string(1) "d"
string(1) "a"


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-09 04:28 UTC] gabri dot ns at gmail dot com
it is already mentioned in a note at the bottom of the page.
still, its true that it would be better if thus note moved up
at the main description.
 [2013-07-09 06:42 UTC] lucas at threeamdesign dot com dot au
Sorry, missed that note. I'm sure many others have and will. I still think it needs the example.
 [2013-07-09 23:38 UTC] cmbecker69 at gmx dot de
It seems to me that the proposed description might be an 
overspecification of the functionality.

According to <http://php.net/function.list>:

| list() only works on numerical arrays and assumes 
| the numerical indices start at 0.

Anything else might be regarded as depeding on the 
implementation, and might change in a future release.
 [2013-07-10 04:02 UTC] lucas at threeamdesign dot com dot au
What's the benefit of breaking the current functionality? I don't think it behaves in an implementation-specific way now, so it shouldn't in the future. It'd be better to show the example with array_values() as well:

<?php
$foo = array(2 => 'a', 'foo' => 'b', 0 => 'c');
$foo[1] = 'd';
var_dump($foo);
echo PHP_EOL;

list($x, $y, $z) = $foo;
var_dump($x, $y, $z);
echo PHP_EOL;

list($x, $y, $z) = array_values($foo);
var_dump($x, $y, $z);
?>

produces:

array(4) {
  [2]=>
  string(1) "a"
  ["foo"]=>
  string(1) "b"
  [0]=>
  string(1) "c"
  [1]=>
  string(1) "d"
}

string(1) "c"
string(1) "d"
string(1) "a"

string(1) "a"
string(1) "b"
string(1) "c"
 [2016-06-25 16:10 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=339494
Log: Fix #65221: Does not adequately explain nature of how list retrieves values from an array
 [2016-06-25 16:10 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-06-25 16:10 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2020-02-07 06:07 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=260be846fd69acf6c5d0d3aeeaf4a1fd08bf0c06
Log: Fix #65221: Does not adequately explain nature of how list retrieves values from an array
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 19:00:01 2026 UTC