Edit report at http://bugs.php.net/bug.php?id=51112&edit=1
ID: 51112 Updated by: ras...@php.net Reported by: post at oliver-schieche dot de Summary: list() misbehaviour Status: To be documented Type: Bug Package: Scripting Engine problem Operating System: Debian (etch) PHP Version: 5.2.12 New Comment: Like Johannes said and Pierre said, writing to a variable you are iterating over gives undefined behaviour. That means it will work in some cases and not in others and may very well change between versions. There is nothing to fix here except perhaps a little note in the documentation. Previous Comments: ------------------------------------------------------------------------ [2010-03-22 01:00:29] post at oliver-schieche dot de Hate to be nagging again, but there's still a problem: it works "as it's supposed to" (read: "as it's not documented") in PHP4, but doesn't in PHP5 with the exception, that the following produces expected results: $a = array('Foo','Bar'); list($a,$b) = $a; $a == 'Foo' ==> TRUE $b == 'Bar' ==> TRUE "both variables are needed during the "list" operation." is a somewhat confusing statement regarding the issue(s) above. ------------------------------------------------------------------------ [2010-03-21 19:52:00] johan...@php.net The order in which the variables are picked up in this case is "undefined behavior" - both variables are needed during the "list" operation. ------------------------------------------------------------------------ [2010-03-18 18:38:12] ka...@php.net Can this either be classfied as a scripting engine bug. If it indeed is a documentation issue then re-classify this as a "To be Documented" documentation issue for the developer that picks this one up. ------------------------------------------------------------------------ [2010-02-22 12:58:56] post at oliver-schieche dot de Why document an obvious bug instead of fixing it? How would you document/explain this? If this works: function ret($array) {return $array;} $b = array('foo','bar'); list($a,$b) = ret($b); But this doesn't: function &ret(&$array) {return $array;} $b = array('foo','bar'); list($a,$b) = ret($b); Then there's a referencing error hidden somewhere... ------------------------------------------------------------------------ [2010-02-22 12:42:52] paj...@php.net That's pretty much the same thing you can see with foreach, the array should not be altered while looping (the array itself, the data of a given element can be altered). No bug here, but should be documented. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/bug.php?id=51112 -- Edit this bug report at http://bugs.php.net/bug.php?id=51112&edit=1