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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Fri Jul 10 03:01:26 2020 UTC