Bug #79911 [Fbk->Nab]: isset - error when using array acess on stdClass
| From: | requinix@php.net | Date: | Tue, 28 Jul 2020 23:49:18 +0000 |
| Subject: | Bug #79911 [Fbk->Nab]: isset - error when using array acess on stdClass | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228262@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: Feedback
+Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
The best place to talk about changing this would be on the internals mailing list. Because it's
not the sort of thing that can simply be changed.
https://www.php.net/mailing-lists.php
Previous Comments:
------------------------------------------------------------------------
[2020-07-28 23:43:52] gregorio at bonfante dot dev
I don't think it is a bug, but it is odd behavior when considering the behavior with an arrays,
resources or scalars.
For example
"""
<?php
$null = null;
$array = [];
$string = 'string';
$int = 0;
$resource = curl_init();
var_dump(isset($undef->x->x->x)); // bool(false)
var_dump(isset($null->x->x->x)); //bool(false)
var_dump(isset($array->x->x->x)); //bool(false)
var_dump(isset($string->x->x->x)); //bool(false)
var_dump(isset($int->x->x->x)); //bool(false)
var_dump(isset($resource->x->x->x)); //bool(false)
var_dump(isset($undef['x']['x']['x'])); //bool(false)
var_dump(isset($null['x']['x']['x'])); //bool(false)
var_dump(isset($array['x']['x']['x'])); //bool(false)
var_dump(isset($string['x']['x']['x'])); //bool(false)
var_dump(isset($int['x']['x']['x'])); //bool(false)
var_dump(isset($resource['x']['x']['x'])); //ON 7.4 bool(false) ON 8
Uncaught Error: Cannot use object of type CurlHandle as array
$obj = new stdClass();
var_dump(isset($obj->x->x->x)); //bool(false)
var_dump(isset($obj['x'])); // Uncaught Error: Cannot use object of type stdClass as array
"""
------------------------------------------------------------------------
[2020-07-28 23:17:22] requinix@php.net
Why do you think this is a bug? Using [] syntax is specifically for arrays and objects implementing
ArrayAccess.
------------------------------------------------------------------------
[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