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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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: Sun Dec 22 01:01:30 2024 UTC