|  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
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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
29 - 2 = ?
Subscribe to this entry?

 [2017-06-10 13:49 UTC] norbert at aimeos dot com
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-10 13:54 UTC]
-Status: Open +Status: Duplicate
 [2017-06-10 13:54 UTC]
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 Feb 25 10:01:26 2024 UTC