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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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
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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 13:01:29 2024 UTC