php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72232 json_decode(json_encode(…), false) makes numeric indices inaccessible
Submitted: 2016-05-17 17:01 UTC Modified: 2016-05-18 11:16 UTC
From: ggreen at mailw dot com Assigned: cmb (profile)
Status: Duplicate Package: json (PECL)
PHP Version: 7.0.6 OS: Mac OS X
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ggreen at mailw dot com
New email:
PHP Version: OS:

 

 [2016-05-17 17:01 UTC] ggreen at mailw dot com
Description:
------------
A json encoded/decoded array is converted back to an array and array_key_exists cannot find the key.

Test script:
---------------
	$arry = [100 => 'Fe', 200 => 'Fi', 300 => 'Fo', 400 => 'Fum'];

	print(array_key_exists(100, $arry) ? '-FOUND' : '-LOST');
	print "\n";

	$obj = json_decode(json_encode($arry));

	print_r($obj);
	print_r((array)$obj);

	print(array_key_exists(100, (array)$obj) ? '-FOUND' : '-LOST');
	print "\n";


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-05-18 11:16 UTC] cmb@php.net
-Summary: See code sample +Summary: json_decode(json_encode(…), false) makes numeric indices inaccessible -Status: Open +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2016-05-18 11:16 UTC] cmb@php.net
This is a duplicate of bug #70925.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 22:01:28 2024 UTC