xref: /PHP-8.1/Zend/tests/gh9916-007.phpt (revision 1173c2e6)
1--TEST--
2Bug GH-9916 007 (Entering shutdown sequence with a fiber suspended in a Generator emits an unavoidable fatal error or crashes)
3--FILE--
4<?php
5$it = new class implements Iterator
6{
7    public function current(): mixed
8    {
9        return null;
10    }
11
12    public function key(): mixed
13    {
14        return 0;
15    }
16
17    public function next(): void
18    {
19    }
20
21    public function rewind(): void
22    {
23        try {
24            print "Before suspend\n";
25            Fiber::suspend();
26            print "Not executed\n";
27        } finally {
28            print "Finally (iterator)\n";
29        }
30    }
31
32    public function valid(): bool
33    {
34        return true;
35    }
36};
37
38$gen = (function() use ($it) {
39    try {
40        yield from $it;
41        print "Not executed\n";
42    } finally {
43        print "Finally\n";
44    }
45})();
46$fiber = new Fiber(function() use ($gen, &$fiber) {
47    $gen->current();
48    print "Not executed";
49});
50$fiber->start();
51?>
52==DONE==
53--EXPECT--
54Before suspend
55==DONE==
56Finally (iterator)
57Finally
58