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

 ID:               51915
 Comment by:       xiezhenye at gmail dot com
 Reported by:      laruence at yahoo dot com dot cn
 Summary:          numeric string key escaped in type change
 Status:           Open
 Type:             Feature/Change Request
 Package:          Scripting Engine problem
 Operating System: linux
 PHP Version:      5.2.13

 New Comment:

there is an easier way to build such an array.



$obj = new stdClass;

$obj->{'123'} = 1;

$arr = (array) $obj;

var_dump($obj);


Previous Comments:
------------------------------------------------------------------------
[2010-05-27 04:15:01] laruence at yahoo dot com dot cn

change bug to Feature , nhancement

------------------------------------------------------------------------
[2010-05-26 08:30:18] laruence at yahoo dot com dot cn

Description:
------------
php treat numeric string key as interge,



bug sometimes there is some exception.



for example:

  while change a std object to array, numeric string key doesn't cast to
number 

Test script:
---------------
<?php

$data = array(

    123 => 'laruence',

    "03"=> 'baidu',

);



$value = json_encode($data);

$obj   = json_decode($value);

$arr   = (array)$obj;

var_dump($arr);

?>

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

  [123]=>

  string(8) "laruence"

  ["03"]=>

  string(5) "baidu"

}



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

  ["123"]=>

  string(8) "laruence"

  ["03"]=>

  string(5) "baidu"

}




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



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

Reply via email to