note 115453 added to function.array-key-exists
| From: | mc dot watras at gmail dot com | Date: | Fri, 25 Jul 2014 08:12:24 +0000 |
| Subject: | note 115453 added to function.array-key-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200054@lists.php.net to get a copy of this message | ||
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
?>
----
Server IP: 72.52.91.14
Probable Submitter: 87.105.187.246
----
Manual Page -- http://php.net/manual/en/function.array-key-exists.php
Edit -- https://master.php.net/note/edit/115453
Del: integrated -- https://master.php.net/note/delete/115453/integrated
Del: useless -- https://master.php.net/note/delete/115453/useless
Del: bad code -- https://master.php.net/note/delete/115453/bad+code
Del: spam -- https://master.php.net/note/delete/115453/spam
Del: non-english -- https://master.php.net/note/delete/115453/non-english
Del: in docs -- https://master.php.net/note/delete/115453/in+docs
Del: other reasons-- https://master.php.net/note/delete/115453
Reject -- https://master.php.net/note/reject/115453
Search -- https://master.php.net/manage/user-notes.php