<?php
class GenClass {
function __construct() { echo "Making GenClass\n"; }
function __destruct() { echo "Destroying GenClass\n"; }
function genInner() { throw new Exception; yield 5; }
}
function genOuter() {
$x = (new GenClass)->genInner(); // $x is now a generator containing the only reference to a GenClass
yield from $x;
}
genOuter()->next();
Making GenClass
Destroying GenClass
Fatal error: Uncaught Exception in /in/iTdQJ:6
Stack trace:
#0 /in/iTdQJ(11): GenClass->genInner()
#1 [internal function]: genOuter()
#2 /in/iTdQJ(14): Generator->next()
#3 {main}
thrown in /in/iTdQJ on line 6
Process exited with code 255.
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
Making GenClass
Destroying GenClass
Fatal error: Uncaught Exception in /in/iTdQJ:6
Stack trace:
#0 /in/iTdQJ(11): GenClass->genInner()
#1 [internal function]: genOuter()
#2 /in/iTdQJ(14): Generator->next()
#3 {main}
thrown in /in/iTdQJ on line 6
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Parse error: syntax error, unexpected '$x' (T_VARIABLE) in /in/iTdQJ on line 11
Process exited with code 255.