|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69601 Miss array key access after json_decode
Submitted: 2015-05-08 10:07 UTC Modified: 2015-05-08 11:18 UTC
From: turin dot tomsk at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: JSON related
PHP Version: 5.5.24 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: turin dot tomsk at gmail dot com
New email:
PHP Version: OS:


 [2015-05-08 10:07 UTC] turin dot tomsk at gmail dot com
When json_encode array and json_decode it, can't get access to array key of object and generate PHP Notice.

Test script:
$a = [1 => 2];
$s = json_encode($a);
$b = @json_decode($s);
$q = (array)$b;
var_dump($q[1]); // PHP Notice:  Undefined offset: 1 in php shell code on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-05-08 11:18 UTC]
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2015-05-08 11:18 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Read the section on "Converting to array" in the manual[1]. What
you actually want to do is

  $q = json_decode($s, true);

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC