|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19930 list() can't get values from associative arrays
Submitted: 2002-10-16 05:02 UTC Modified: 2002-10-24 21:27 UTC
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: flying at dom dot natm dot ru Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.3 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: flying at dom dot natm dot ru
New email:
PHP Version: OS:


 [2002-10-16 05:02 UTC] flying at dom dot natm dot ru
list() function can only operate with indexed arrays, but it must also work with associative arrays, otherwise it can cause confusions.

Take a look at the following example:
$array1 = array('aaa','bbb','ccc');
$array2 = array('a'=>'aaa','b'=>'bbb','c'=>'ccc');
list($a,$b,$c) = $array1;
echo "$a\n$b\n$c\n";
list($a,$b,$c) = $array2;
echo "$a\n$b\n$c\n";

First list() invocation works well but second one throws notices about undefined array indexes and don't work at all. 
As a workaround it is possible to use:
list() = array_values($array);
but it is not a way to go.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-16 06:23 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

list() requires numeric index. That's why pg|mysql_fetch_array(),etc returns both numeric and string indexed element.

 [2002-10-21 03:24 UTC] flying at dom dot natm dot ru
Yes, i know and this is a reason for this bug. 

 Instead of requiring numeric indexes list() must invoke array_values() transparently if it is used in combination with associative array. Otherwise it mean that PHP actually have 2 types of arrays with partial compatibility.

 These duplicates of array values looks very silly for me, there must be one way of handling every array without necessarity of its additional analize into user's code.
 [2002-10-21 17:15 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

 [2002-10-24 21:27 UTC]
I agree, one thread where this was discussed is here:

Odds are list() will remain as is and not change.  Although fwiw, I feel it should rely on the array values too.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 23 09:03:33 2021 UTC