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

 ID:               52321
 Updated by:       ras...@php.net
 Reported by:      saltybaldyev at gmx dot com
 Summary:          list() fails under a mere condition
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          Variables related
 Operating System: linux,windows
 PHP Version:      5.3.2

 New Comment:

You are overwriting the variable you are iterating over.  Just like with
a foreach 

loop, there is no defined behaviour for that.  In this case it is
assigned things 

right to left so $b gets set to "yeah" first and then $a gets set to the
first 

array element of "yeah" which, since it is a string, is 'y'.


Previous Comments:
------------------------------------------------------------------------
[2010-07-12 20:58:28] saltybaldyev at gmx dot com

the same if we do list($a,$b,$c)=$c, list($a,$c,$b)=$c and so on.



i guess such assignments only work properly in case its right part goes
to list() first: list(--> $c <--,$a1,$a2,$a3,...)=$c

------------------------------------------------------------------------
[2010-07-12 20:52:11] saltybaldyev at gmx dot com

Description:
------------
let $b=array(# , #).

then



list($a,$b) = $b



fails.



moar precise: after the assigment we'd get



$b = $b[1],

$a = {

  $b[1][0], if $b[1] is a string/array

  NULL, if $b[1] is a number

}



if $b[1] is an object we'd get a fatal error 'cant convert
object->array'.





//////////////////



it works correctly if we try list($b,$a)=$b. so an easy fix could be
forged in just 2 additional steps: swap arguments * do the usual work *
swap results

Test script:
---------------
$a = 1;

$b = array('ohno','yeah');

list($a,$b) = $b;

print_r(array('a'=>$a,'b'=>$b));

Expected result:
----------------
Array

(

    [a] => ohno

    [b] => yeah

)



Actual result:
--------------
Array

(

    [a] => y

    [b] => yeah

)




------------------------------------------------------------------------



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

Reply via email to