Req->Bug #79911 [Opn->Fbk]: isset - error when using array acess on stdClass
| From: | requinix@php.net | Date: | Tue, 28 Jul 2020 23:17:22 +0000 |
| Subject: | Req->Bug #79911 [Opn->Fbk]: isset - error when using array acess on stdClass | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228260@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79911&edit=1
ID: 79911
Updated by: requinix@php.net
Reported by: gregorio at bonfante dot dev
Summary: isset - error when using array acess on stdClass
-Status: Open
+Status: Feedback
-Type: Feature/Change Request
+Type: Bug
-Package: Scripting Engine problem
+Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Why do you think this is a bug? Using [] syntax is specifically for arrays and objects implementing
ArrayAccess.
Previous Comments:
------------------------------------------------------------------------
[2020-07-28 23:14:39] gregorio at bonfante dot dev
Description:
------------
Similar to https://bugs.php.net/bug.php?id=55223
Not a bug, but still not what I expected.
Using array access results in an error if the subject is an object without ArrayAccess.
Not sure about the solution as I don't have familiarity with the PHP internals.
I was able to adjust this behavior adding
"""
else if(!check_empty) {
return 0;
}
"""
to 'zend_std_has_dimension' on Zend/zend_object_handlers.c
before the "else { zend_bad_array_access(ce); return 0; }"
Test script:
---------------
<?php
$a = [];
$o = new stdClass();
var_dump(isset($a->prop));
var_dump(isset($o[0]));
Expected result:
----------------
bool(false)
bool(false)
Actual result:
--------------
bool(false)
Fatal error: Uncaught Error: Cannot use object of type stdClass as array in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79911&edit=1