|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2015-11-17 03:01 UTC] nhojohl at gmail dot com
  [2016-05-18 11:21 UTC] cmb@php.net
 
-Status:      Open
+Status:      Wont fix
-Assigned To:
+Assigned To: cmb
  [2016-05-18 11:21 UTC] cmb@php.net
  [2016-11-14 18:32 UTC] ajf@php.net
 
-Status: Wont fix
+Status: Closed
  [2016-11-14 18:32 UTC] ajf@php.net
  [2016-11-14 18:36 UTC] ajf@php.net
 
-Assigned To: cmb
+Assigned To: ajf
 | |||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 15:00:01 2025 UTC | 
Description: ------------ Bug converting json_decoded-d object to array. First seen in PHP 5.4. Confirmed in PHP 5.6.15. See the test script. We have a simple array $a. Next we convert it to JSON and back. But after transcoding we can not access the array's values and get NULL or "Notice: Undefined offset: 1". If replace the line "$a = (array)json_decode(json_encode($a));" with "$a = (array)((object)$a);" everything is OK, converted array's values are accessible. The test script output is: array(2) { [1] => string(7) "value 1" [2] => string(7) "value 2" } string(7) "value 1" string(7) "value 1" array(2) { '1' => string(7) "value 1" '2' => string(7) "value 2" } NULL NULL Test script: --------------- <? error_reporting(0); $a = ['1' => 'value 1', '2' => 'value 2']; var_dump($a); var_dump($a[1]); var_dump($a['1']); $a = (array)json_decode(json_encode($a)); var_dump($a); var_dump($a[1]); var_dump($a['1']); ?> Expected result: ---------------- The values of the converted array must be accessible Actual result: -------------- NULL or Notice: Undefined offset: 1