php-src/Zend/tests/gh9916-011.phpt
Arnaud Le Blanc 1173c2e64a
Prevent dtor of generator in suspended fiber (#10462)
Generators that suspended a fiber should not be dtor because they will be
executed during the fiber dtor.

Fiber dtor throws an exception in the fiber's context in order to unwind and
execute finally blocks, which will also properly dtor the generator.

Fixes GH-9916
2023-01-27 19:32:25 +01:00

42 lines
832 B
PHP

--TEST--
Bug GH-9916 011 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes)
--FILE--
<?php
$gen = (function() {
$x = new stdClass;
print "Before yield\n";
$from = (function () {
$x = new stdClass;
print "Before yield 2\n";
yield;
print "Before suspend\n";
Fiber::suspend();
print "Not executed\n";
yield;
})();
try {
yield from $from;
} finally {
$from->next();
}
})();
$fiber = new Fiber(function () use ($gen, &$fiber) {
print "Before current\n";
$gen->current();
print "Before next\n";
$gen->next();
print "Not executed\n";
});
$fiber->start();
?>
==DONE==
--EXPECT--
Before current
Before yield
Before yield 2
Before next
Before suspend
==DONE==