<?php class InfiniteLoggingIterator implements Iterator { public function __construct() { $this->position = 0; } public function rewind() { echo __METHOD__, PHP_EOL; $this->position = 0; } public function current() { echo __METHOD__, PHP_EOL; return $this->position; } public function key() { echo __METHOD__, PHP_EOL; return $this->position; } public function next() { echo __METHOD__, PHP_EOL; ++$this->position; } public function valid() { echo __METHOD__, PHP_EOL; return true; } } $i = new LimitIterator(new InfiniteLoggingIterator, 0, 2); echo "Rewinding outer iterator\n"; $i->rewind(); echo "\nGetting 1st value\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 2nd value\n"; $i->next(); echo "\nGetting 2nd (and last) value\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 3rd value\n"; $i->next(); echo "\nGetting 3rd value (beyond limit)\n"; echo $i->valid() ? "Valid\n" : "Not valid\n"; echo "Current key: ", $i->key() ?? 'NULL', "\n"; echo "Current value: ", $i->current() ?? 'NULL', "\n"; echo "Proceeding to 4th value!\n"; $i->next();
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`