|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79911 isset - error when using array acess on stdClass
Submitted: 2020-07-28 23:14 UTC Modified: 2020-07-28 23:49 UTC
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: gregorio at bonfante dot dev Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: gregorio at bonfante dot dev
New email:
PHP Version: OS:


 [2020-07-28 23:14 UTC] gregorio at bonfante dot dev
Similar to
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:
$a = [];
$o = new stdClass();

Expected result:

Actual result:
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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-28 23:17 UTC]
-Status: Open +Status: Feedback -Type: Feature/Change Request +Type: Bug -Package: Scripting Engine problem +Package: *General Issues
 [2020-07-28 23:17 UTC]
Why do you think this is a bug? Using [] syntax is specifically for arrays and objects implementing ArrayAccess.
 [2020-07-28 23:43 UTC] 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

$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:49 UTC]
-Status: Feedback +Status: Not a bug
 [2020-07-28 23:49 UTC]
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.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Oct 04 23:05:52 2022 UTC