Bug #74739 [Opn->Dup]: isset() doesn't work on stdClass objects converted to arrays
| From: | requinix@php.net | Date: | Sat, 10 Jun 2017 13:54:34 +0000 |
| Subject: | Bug #74739 [Opn->Dup]: isset() doesn't work on stdClass objects converted to arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209467@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74739&edit=1
ID: 74739
Updated by: requinix@php.net
Reported by: norbert at aimeos dot com
Summary: isset() doesn't work on stdClass objects converted
to arrays
-Status: Open
+Status: Duplicate
Type: Bug
Package: Scripting Engine problem
Operating System: Ubuntu
PHP Version: 7.0.20
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2017-06-10 13:49:16] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74739&edit=1