Bug #74822 [Com]: A json_decode() cast as an array fails with numeric keys

From: Date: Tue, 27 Jun 2017 12:21:03 +0000
Subject: Bug #74822 [Com]: A json_decode() cast as an array fails with numeric keys
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209702@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74822&edit=1 ID: 74822 Comment by: maggus dot staab at googlemail dot com Reported by: dominic at sussex dot ac dot uk Summary: A json_decode() cast as an array fails with numeric keys Status: Open Type: Bug Package: Unknown/Other Function Operating System: Linux PHP Version: 5.6.30 Block user comment: N Private report: N New Comment: seems to be fixed on 7.2+ https://3v4l.org/vvikf Previous Comments: ------------------------------------------------------------------------ [2017-06-27 12:12:15] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74822&edit=1

« previous php.bugs (#209702) next »