vCallback = $vCallback; $this->aCallback = $options['accept'] ?? null; } public function next(): void { $this->cache = []; parent::next(); } public function rewind(): void { $this->rewound = true; $this->cache = []; parent::rewind(); } public function accept(): bool { $inner = $this->getInnerIterator(); '@phan-var Iterator $inner'; $value = ( $this->vCallback )( $inner->current() ); $ok = ( $this->aCallback ) ? ( $this->aCallback )( $value ) : true; if ( $ok ) { $this->cache['current'] = $value; } return $ok; } #[\ReturnTypeWillChange] public function key() { $this->init(); return parent::key(); } public function valid(): bool { $this->init(); return parent::valid(); } #[\ReturnTypeWillChange] public function current() { $this->init(); if ( parent::valid() ) { return $this->cache['current']; } else { return null; // out of range } } /** * Obviate the usual need for rewind() before using a FilterIterator in a manual loop */ protected function init() { if ( !$this->rewound ) { $this->rewind(); } } }