update page now

Voting

: six plus two?
(Example: nine)

The Note You're Voting On

hello at rayfung dot hk
4 years ago
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;
 }
}
?>

<< Back to user notes page

AltStyle によって変換されたページ (->オリジナル) /