Bug #74822 [Opn->Csd]: A json_decode() cast as an array fails with numeric keys

From: Date: Tue, 27 Jun 2017 12:23:20 +0000
Subject: Bug #74822 [Opn->Csd]: 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-209703@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 Updated by: nikic@php.net Reported by: dominic at sussex dot ac dot uk Summary: A json_decode() cast as an array fails with numeric keys -Status: Open +Status: Closed Type: Bug Package: Unknown/Other Function Operating System: Linux PHP Version: 5.6.30 -Assigned To: +Assigned To: nikic Block user comment: N Private report: N New Comment: See also: https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts Previous Comments: ------------------------------------------------------------------------ [2017-06-27 12:21:02] maggus dot staab at googlemail dot com seems to be fixed on 7.2+ https://3v4l.org/vvikf ------------------------------------------------------------------------ [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 (#209703) next »