1--TEST-- 2Creating an infinite fibonacci list using a generator 3--FILE-- 4<?php 5 6function fib() { 7 list($a, $b) = [1, 1]; 8 while (true) { 9 yield $b; 10 list($a, $b) = [$b, $a + $b]; 11 } 12} 13 14foreach (fib() as $n) { 15 if ($n > 1000) break; 16 17 var_dump($n); 18} 19 20?> 21--EXPECT-- 22int(1) 23int(2) 24int(3) 25int(5) 26int(8) 27int(13) 28int(21) 29int(34) 30int(55) 31int(89) 32int(144) 33int(233) 34int(377) 35int(610) 36int(987) 37