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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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: Sun Nov 24 18:01:32 2024 UTC