Интерфейс SeekableIterator SeekableIterator
&reftitle.intro; Итератор Seekable.
&reftitle.interfacesynopsis; SeekableIterator extends Iterator &Methods; &InheritedMethods;
&reftitle.examples; Простое использование Этот пример показывает как создаётся пользовательский итератор SeekableIterator, который ищет и обрабатывает недопустимую позицию. array[$position])) { throw new OutOfBoundsException("Недопустимая позиция ($position)"); } $this->position = $position; } /* Методы, которые требует интерфейс Iterator */ public function rewind() { $this->position = 0; } public function current() { return $this->array[$this->position]; } public function key() { return $this->position; } public function next() { ++$this->position; } public function valid() { return isset($this->array[$this->position]); } } try { $it = new MySeekableIterator(); echo $it->current(), "\n"; $it->seek(2); echo $it->current(), "\n"; $it->seek(1); echo $it->current(), "\n"; $it->seek(10); } catch (OutOfBoundsException $e) { echo $e->getMessage(); } ?> ]]> &example.outputs.similar;
&reference.spl.entities.seekableiterator;