php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74739 isset() doesn't work on stdClass objects converted to arrays
Submitted: 2017-06-10 13:49 UTC Modified: 2017-06-10 13:54 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: norbert at aimeos dot com Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 7.0.20 OS: Ubuntu
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: norbert at aimeos dot com
New email:
PHP Version: OS:

 

 [2017-06-10 13:49 UTC] norbert at aimeos dot com
Description:
------------
When converting stdClass objects to arrays (e.g. from json_decode()), they look exactly like arrays when using print_r() or var_dump() but isset() or array_key_exists() doesn't work. Then testing for keys, these functions always return false.

Test script:
---------------
check =  new \stdClass();
$check->{"12"} = 37;
$check2 = (array) $check;


Expected result:
----------------
isset($check2[12]); -> true
isset($check2["12"]); -> true


Actual result:
--------------
isset($check2[12]); -> false
isset($check2["12"]); -> false


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-10 13:54 UTC] requinix@php.net
-Status: Open +Status: Duplicate
 [2017-06-10 13:54 UTC] requinix@php.net
It's not just isset: numeric string properties on an object aren't handled well when casting to an array.

Use get_object_vars() instead.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC