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
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: rynkiewiczm at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 16:01:30 2025 UTC