Edit report at http://bugs.php.net/bug.php?id=51112&edit=1

 ID:               51112
 User updated by:  post at oliver-schieche dot de
 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:

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.


Previous Comments:
------------------------------------------------------------------------
[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.

------------------------------------------------------------------------
[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/bug.php?id=51112&edit=1

Reply via email to