3v4l.org

run code in 300+ PHP versions simultaneously
<?php function emptyGenerator(): Generator { var_dump('Generator function started'); if (false) { yield 'some value'; } var_dump('Generator function finished'); } $generator = emptyGenerator(); var_dump('About to call $generator->valid()'); if ($generator->valid()) { var_dump('Generator is not empty, traversing'); foreach ($generator as $value) { var_dump('Generator yielded '.$value); } var_dump('Finished traversing generator'); } else { var_dump('Generator is empty'); }
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
string(33) "About to call $generator->valid()" string(26) "Generator function started" string(27) "Generator function finished" string(18) "Generator is empty"
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
52.82 ms | 407 KiB | 5 Q