3v4l.org

run code in 300+ PHP versions simultaneously
<?php class test { public $generator; public function __construct() { $generator = function() { yield from [1,1,2,3,5,8,13,21]; }; $this->generator = $generator(); } public function getValue() { while($this->generator->valid()) { $latitude = $this->generator->current(); $this->generator->next(); return $latitude; } throw new RangeException('End of line'); } } $line = new test(); try { for($i = 0; $i < 10; ++$i) { echo $line->getValue(); echo PHP_EOL; } } catch (Exception $e) { echo $e->getMessage(); }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
1 1 2 3 5 8 13 21 End of line
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 1 1 2 3 5 8 13 21 End of line

preferences:
152.88 ms | 402 KiB | 173 Q