Bug #74859 [Fbk->Opn]: json_decode unexpected behaviour
| From: | emimarz at gmail dot com | Date: | Thu, 06 Jul 2017 14:57:05 +0000 |
| Subject: | Bug #74859 [Fbk->Opn]: json_decode unexpected behaviour | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209856@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74859&edit=1
ID: 74859
User updated by: emimarz at gmail dot com
Reported by: emimarz at gmail dot com
Summary: json_decode unexpected behaviour
-Status: Feedback
+Status: Open
Type: Bug
Package: JSON related
Operating System: linux
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
this two return NULL
var_dump($json['1']); // incorrect result
var_dump($json[1]); // incorrect result
I trying to access an element existent but return NULL
the expected return is something that is not NULL because that element exists
Previous Comments:
------------------------------------------------------------------------
[2017-07-05 18:33:40] peehaa@php.net
What unexpected behavior?
Please explain what is expected and why and what the actual result is.
------------------------------------------------------------------------
[2017-07-05 18:24:36] emimarz at gmail dot com
Description:
------------
this unexpected behaviour happen on php 5.* and 7.1 with json_decode
Test script:
---------------
<?php
$son = '{
"1":{ "id":"1", "name":"jack" },
"2":{ "id":"2", "name":"john" }
}';
$json = (array) json_decode($son);
//var_dump($json);
var_dump($json['1']); // incorrect result
var_dump($json[1]); // incorrect result
$json = json_decode($son,true);
var_dump($json['1']); // correct result
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74859&edit=1