php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75423 Isset not work on array with stdClasses
Submitted: 2017-10-24 09:05 UTC Modified: 2017-10-24 09:21 UTC
From: rynkiewiczm at gmail dot com Assigned:
Status: Duplicate Package: Arrays related
PHP Version: 7.1.10 OS:
Private report: No CVE-ID: None
 [2017-10-24 09:05 UTC] rynkiewiczm at gmail dot com
Description:
------------
When you convert array from stdClass you will get array with many stdClasses.
Isset on index of array element will not work correctly if you try it.

Test script:
---------------
$id = '11400';
$json = '{"11400":{"test":"1","test":"2","xyz":"abc"}}';
// yes, I know second parametr, but it should work too
$decodedJson = (array)json_decode($json);
if (isset($decodedJson[$id])) {
    echo 'exists!';
} else {
    echo 'not exists!';
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-24 09:21 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2017-10-24 09:21 UTC] requinix@php.net
If I had a nickel...

This has been fixed in 7.2.
https://wiki.php.net/rfc/convert_numeric_keys_in_object_array_casts
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jan 17 23:01:24 2019 UTC