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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
28 - 16 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Wed Apr 24 13:01:29 2024 UTC