php.net |  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
6 + 13 = ?
Subscribe to this entry?

 
 [2017-06-27 12:12 UTC] dominic at sussex dot ac dot uk
Description:
------------
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;

var_dump($aa['10']);

Expected result:
----------------
string(3) "abc"

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-27 12:21 UTC] maggus dot staab at googlemail dot com
seems to be fixed on 7.2+

https://3v4l.org/vvikf
 [2017-06-27 12:23 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Jul 03 20:03:49 2022 UTC