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

 ID:          51682
 Comment by:  pavel dot lisa at centrum dot cz
 Reported by: david at grudl dot com
 Summary:     (array) casting and numeric keys
 Status:      Open
 Type:        Bug
 Package:     Arrays related
 PHP Version: Irrelevant

 New Comment:

I'd say there is no error in the way PHP handles this, as you are
accessing 

$obj->{'10'} by a string key ( '10' === "10" => true ). 



$obj = new stdClass;

$obj->{"10"} = 'as string';



$arr = (array) $obj;

$arr["10"] = 'as string again';



var_dump($arr);



would then produce something like



array(1) {

  ["10"]=>

  string(10) "as string again"

}


Previous Comments:
------------------------------------------------------------------------
[2010-04-28 15:30:25] david at grudl dot com

Description:
------------
Casting to (array) handles numeric keys wrong way:





Test script:
---------------
$obj = new stdClass;

$obj->{'10'} = 'as string';



$arr = (array) $obj;

$arr[10] = 'as integer';



var_dump($arr);



Expected result:
----------------
array(1) {

  [10]=>

  string(10) "as integer"

}





Actual result:
--------------
array(2) {

  ["10"]=>

  string(9) "as string"

  [10]=>

  string(10) "as integer"

}






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



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

Reply via email to