|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74822 A json_decode() cast as an array fails with numeric keys
Submitted: 2017-06-27 12:12 UTC Modified: 2017-06-27 12:23 UTC
From: dominic at sussex dot ac dot uk Assigned: nikic (profile)
Status: Closed Package: Unknown/Other Function
PHP Version: 5.6.30 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: dominic at sussex dot ac dot uk
New email:
PHP Version: OS:


 [2017-06-27 12:12 UTC] dominic at sussex dot ac dot uk
Casting a decoded simple json structure into an array doesn't allow lookups by key if the key is numeric.

Test script:
$a = json_decode('{"b": {"c": {"10": "abc", "11": "def"}}}');

$aa = (array)$a->b->c;


Expected result:
string(3) "abc"

Actual result:
Notice: Undefined offset: 10 in /in/d0290 on line 7


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-27 12:21 UTC] maggus dot staab at googlemail dot com
seems to be fixed on 7.2+
 [2017-06-27 12:23 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 17 10:01:28 2024 UTC