If your class implements also ArrayAccess interface, you could use as valid() bodyfunction valid(){ return $this->offsetExists($this->position);}
(PHP 5, PHP 7, PHP 8)
Iterator::valid — Проверяет корректность текущей позиции
Метод вызывается после функций Iterator::rewind() и Iterator::next() чтобы проверить, допустима ли текущая позиция.
Сигнатура функции не содержит параметров.
If your class implements also ArrayAccess interface, you could use as valid() bodyfunction valid(){ return $this->offsetExists($this->position);}
If Iterator::valid() returns false, the foreach() loop will be terminated.