<?php class BadIterator implements Iterator { private $data = [1, 2, 3, 4, 5]; private $pos = 0; public function current() { return $this; } public function key() { return $this->pos; } public function next() { $this->pos++; } public function rewind() { $this->pos = 0; } public function valid() { return $this->pos < count($this->data); } public function __toString() { return (string) $this->data[$this->pos]; } } echo "Direct iteration:\n"; foreach (new BadIterator as $val) { echo "$val\n"; } echo "Caching iteration:\n"; foreach (new CachingIterator(new BadIterator) as $val) { echo "$val\n"; }
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`