Edit report at https://bugs.php.net/bug.php?id=63007&edit=1
ID: 63007 Updated by: larue...@php.net Reported by: janfili+phpbugs at gmail dot com Summary: json functions corrupt arrayindizes -Status: Open +Status: Not a bug Type: Bug Package: JSON related Operating System: Linux ubuntu1010 PHP Version: 5.3.16 Block user comment: N Private report: N New Comment: similar to https://bugs.php.net/bug.php?id=51915 Previous Comments: ------------------------------------------------------------------------ [2012-09-04 08:21:08] reeze dot xia at gmail dot com Yes, it will not accessible anymore if you have property with string number. since array handle keys different from objects. ------------------------------------------------------------------------ [2012-09-04 08:19:17] reeze dot xia at gmail dot com Ah, I'm sorry, the bug ID: #54082, I can't find the report right now. will post that later ------------------------------------------------------------------------ [2012-09-04 08:18:29] janfili+phpbugs at gmail dot com using this var_dump($array['1']); as the last statement will not help either ------------------------------------------------------------------------ [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