3v4l.org

run code in 300+ PHP versions simultaneously
<?php class It implements \IteratorAggregate { public $gen; public function getIterator(): \Generator { yield 'foo'; $this->gen->throw(new Exception()); var_dump("not executed"); } public function __destruct() { var_dump(__METHOD__); } } function f($it) { try { var_dump(new stdClass, yield from $it); } finally { var_dump(__FUNCTION__); } } $it = new It(); $gen = f($it); $it->gen = $gen; var_dump($gen->current()); $gen->next(); gc_collect_cycles(); ?>
Output for 8.3.25 - 8.3.28, 8.4.12 - 8.4.14, 8.5.0 - 8.5.1
string(3) "foo" string(1) "f" Fatal error: Uncaught Error: Cannot resume an already running generator in /in/5pi53:10 Stack trace: #0 /in/5pi53(10): Generator->throw(Object(Exception)) #1 /in/5pi53(22): It->getIterator() #2 [internal function]: f(Object(It)) #3 /in/5pi53(33): Generator->next() #4 {main} thrown in /in/5pi53 on line 10 string(14) "It::__destruct"
Process exited with code 255.
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.
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.22, 8.3.0 - 8.3.10, 8.4.1 - 8.4.11
string(3) "foo" string(1) "f"
Process exited with code 139.
Output for 8.2.23 - 8.2.29, 8.3.11 - 8.3.24
string(3) "foo" string(1) "f" Fatal error: Uncaught Exception in /in/5pi53:10 Stack trace: #0 /in/5pi53(22): It->getIterator() #1 [internal function]: f(Object(It)) #2 /in/5pi53(33): Generator->next() #3 {main} thrown in /in/5pi53 on line 10 string(14) "It::__destruct"
Process exited with code 255.

preferences:
86.47 ms | 411 KiB | 5 Q