_offset = $offset; $this->_count = $count; } /** * @return string representation of the instance */ public function serialize() { return serialize(array( 'it' => $this->getInnerIterator(), 'offset' => $this->_offset, 'count' => $this->_count, 'pos' => $this->getPosition(), )); } public function __serialize(): array { return array( 'it' => $this->getInnerIterator(), 'offset' => $this->_offset, 'count' => $this->_count, 'pos' => $this->getPosition(), ); } /** * @param string $data representation of the instance */ public function unserialize($data) { $dataArr = unserialize($data); $this->__construct($dataArr['it'], $dataArr['offset'], $dataArr['count']); $this->seek($dataArr['pos']+$dataArr['offset']); } public function __unserialize(array $data): void { $this->__construct($data['it'], $data['offset'], $data['count']); $this->seek($data['pos']+$data['offset']); } /** * Returns value of the Iterator * * @param int $offset * @return mixed */ #[\ReturnTypeWillChange] public function offsetGet($offset) { $currentOffset = $this->key(); $this->seek($offset); $current = $this->current(); $this->seek($currentOffset); return $current; } /** * Does nothing * Required by the ArrayAccess implementation * * @param int $offset * @param mixed $value */ public function offsetSet($offset, $value): void { } /** * Determine if a value of Iterator is set and is not NULL * * @param int $offset */ public function offsetExists($offset): bool { if ($offset > 0 && $offset < $this->_count) { try { $currentOffset = $this->key(); $this->seek($offset); $current = $this->current(); $this->seek($currentOffset); return null !== $current; } catch (OutOfBoundsException $e) { // reset position in case of exception is assigned null $this->rewind(); $this->seek($currentOffset); return false; } } return false; } /** * Does nothing * Required by the ArrayAccess implementation * * @param int $offset */ public function offsetUnset($offset): void { } }