Edit report at https://bugs.php.net/bug.php?id=63007&edit=1
ID: 63007
Comment by: janfili+phpbugs at gmail dot com
Reported by: janfili+phpbugs at gmail dot com
Summary: json functions corrupt arrayindizes
Status: Open
Type: Bug
Package: JSON related
Operating System: Linux ubuntu1010
PHP Version: 5.3.16
Block user comment: N
Private report: N
New Comment:
using this var_dump($array['1']); as the last statement will not help either
Previous Comments:
------------------------------------------------------------------------
[2012-09-04 08:04:22] reeze dot xia at gmail dot com
This is not a problem of JSON itself.
but. array vs object conversion. and it was documented:
http://www.php.net/manual/en/language.types.array.php#language.types.array.casti
ng
after json_encode key: 1 was encoded as string.
In object properties and only been string key.
but after convert to array, it will not be able to accessed since.
if the key will be changed to number key if possible.
similar to https://bugs.php.net/bug.php?id=54082
------------------------------------------------------------------------
[2012-09-04 07:38:41] janfili+phpbugs at gmail dot com
Description:
------------
after json en/decoding the original array index cant be used to retrieve the values.
however foreach and all other array-related functions work as expected.
Test script:
---------------
<?
$class = new stdClass();
$class->field = 'foo';
var_dump($class);
$array = array(1 => $class);
var_dump($array);
$json_sting = json_encode($array);
var_dump($json_sting);
$array_obj = json_decode($json_sting);
var_dump($array_obj);
$array = (array) $array_obj;
var_dump($array);
var_dump($array[1]);
?>
Expected result:
----------------
output of last var_dump is expected to be
object(stdClass)#3 (1) {
["field"]=>
string(3) "foo"
}
Actual result:
--------------
NULL
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63007&edit=1