rewind(); } ############################################################################# # Implémentation par défaut private $setup = false; private $valid = false; private $toredown = true; private $index = 0; protected $key; protected $item = null; function key() { return $this->key; } function current() { return $this->item; } function next(): void { if ($this->toredown) return; $this->valid = false; try { $item = $this->_next($key); } catch (NoMoreDataException $e) { $this->beforeClose(); try { $this->_teardown(); } catch (Exception $e) { } $this->toredown = true; return; } $this->cook($item); $this->item = $item; if ($key !== null) { $this->key = $key; } else { $this->index++; $this->key = $this->index; } $this->valid = true; } function rewind(): void { if ($this->setup) { if (!$this->toredown) { $this->beforeClose(); try { $this->_teardown(); } catch (Exception $e) { } } $this->setup = false; $this->valid = false; $this->toredown = true; $this->index = 0; $this->key = null; $this->item = null; } } function valid(): bool { if (!$this->setup) { try { $this->_setup(); } catch (Exception $e) { } $this->setup = true; $this->toredown = false; $this->beforeIter(); $this->next(); } return $this->valid; } }