note 125849 added to class.arrayobject
| From: | hello at rayfung dot hk | Date: | Mon, 22 Feb 2021 01:38:44 +0000 |
| Subject: | note 125849 added to class.arrayobject | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219088@lists.php.net to get a copy of this message | ||
If you want to use built-in array function with ArrayObject, store the iterator instance and return
the value as reference in offsetGet.
<?php
class Collection extends \ArrayObject {
public function __construct(array $data = [])
{
if (!\is_array($data) && !\array_key_exists('ArrayAccess',
class_implements($data))) {
$data = [$data];
}
$this->iterator = $this->getIterator();
parent::__construct($data);
}
public function &offsetGet($index)
{
$value = &$this->iterator[$index] ?? null;
return $value;
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 202.155.194.34)
----
Manual Page -- http://php.net/manual/en/class.arrayobject.php
Edit -- https://master.php.net/note/edit/125849
Del: integrated -- https://master.php.net/note/delete/125849/integrated
Del: useless -- https://master.php.net/note/delete/125849/useless
Del: bad code -- https://master.php.net/note/delete/125849/bad+code
Del: spam -- https://master.php.net/note/delete/125849/spam
Del: non-english -- https://master.php.net/note/delete/125849/non-english
Del: in docs -- https://master.php.net/note/delete/125849/in+docs
Del: other reasons-- https://master.php.net/note/delete/125849
Reject -- https://master.php.net/note/reject/125849
Search -- https://master.php.net/manage/user-notes.php