3v4l.org

run code in 300+ PHP versions simultaneously
<?php class InfiniteNumbers implements Iterator { public $start; public $current; public function __construct($start) { $this->start = $start; $this->current = $start; } public function next() { echo "next called\n"; $this->current++; } public function current() { echo "current called\n"; return $this->current; } public function key() { echo "key called\n"; return $this->current; } public function rewind() { echo "rewind called\n"; $this->current = $this->start; } public function valid() { echo "valid called\n"; return true; } } $infinite = new InfiniteNumbers(1); var_dump($infinite); foreach($infinite as $number) { if($number > 10) { break; } echo $number."\n"; }

preferences:
53.25 ms | 402 KiB | 5 Q