#19930 [Opn->Bgs]: list() can't get values from associative arrays
| From: | iliaa@php.net | Date: | Mon, 21 Oct 2002 22:15:55 +0000 |
| Subject: | #19930 [Opn->Bgs]: list() can't get values from associative arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-22998@lists.php.net to get a copy of this message | ||
ID: 19930
Updated by: iliaa@php.net
Reported By: flying@dom.natm.ru
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Windows 2000
PHP Version: 4.2.3
New Comment:
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 http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.
Thank you for your interest in PHP.
Previous Comments:
------------------------------------------------------------------------
[2002-10-21 03:24:54] flying@dom.natm.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-16 06:23:19] yohgaki@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
list() requires numeric index. That's why pg|mysql_fetch_array(),etc
returns both numeric and string indexed element.
------------------------------------------------------------------------
[2002-10-16 05:02:42] flying@dom.natm.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:
<?php
$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.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19930&edit=1