#51112 [Com]: list() misbehaviour

From: Date: Mon, 22 Feb 2010 12:58:56 +0000
Subject: #51112 [Com]: list() misbehaviour
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3956@lists.php.net to get a copy of this message
ID: 51112 Comment by: post at oliver-schieche dot de Reported By: post at oliver-schieche dot de Status: Open Bug Type: Documentation problem Operating System: Debian (etch) PHP Version: 5.2.12 New Comment: 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... Previous Comments: ------------------------------------------------------------------------ [2010-02-22 12:42:52] pajoye@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. ------------------------------------------------------------------------ [2010-02-22 12:38:52] post at oliver-schieche dot de Description: ------------ When assigning an array to a list() of variables and using the input array as a member of that list(), unexpected results are returned. Reproduce code: --------------- $b = array('foo','bar'); list($a,$b) = $b; $c = array('foo','bar'); list($c,$d) = $c; Expected result: ---------------- $a == $c == 'foo' $b == $d == 'bar' Actual result: -------------- $a == 'b' $b == 'bar' $c == 'foo' $d == 'bar' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=51112&edit=1

« previous php.doc.bugs (#3956) next »