note 115453 deleted from function.array-key-exists by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 20:45:57 +0000 |
| Subject: | note 115453 deleted from function.array-key-exists by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218770@lists.php.net to get a copy of this message | ||
Note Submitter: mc dot watras at gmail dot com
----
array_key_exists doesn't work with objects implementing ArrayAccess interface. It also ignores
possible __get() method in such objects, despite the fact it accepts object as a second parameter.
It works only with 'real' properties.
<?php
class A implements ArrayAccess {
public $data;
public function offsetExists($offset) {
return isset($this->data[$offset]);
}
public function __get($property) {
return $this->data[$property];
}
}
$a = new A();
$a->data['somekey'] = 1;
var_dump(array_key_exists('somekey', $a)); // returns false
var_dump(array_key_exists('data', $a)); // returns true
?>