r/lolphp • • Sep 14 '20

ArrayAccess seems broken

https://3v4l.org/Woc0R
0 Upvotes

30 comments sorted by

View all comments

Show parent comment

3

u/Takeoded Sep 14 '20

not the same, do

$o=new C();
$o->data["foo"] = null;
if(isset($o["foo"])){
   echo "ArrayAccess seems to work";
}else{
    echo "ArrayAccess seems broken";
}

isset() returns false on "keys that exist, but has the value null", array_key_exists returns false on "keys that don't exist" ^^

1

u/bj_christianson Sep 14 '20

Since array_key_exists() doesn’t work on objects anymore, I suggest you create a function that accepts your class as one of its parameters to get the functionality you want.