xref: /PHP-8.4/Zend/tests/gh15275-002.phpt (revision c767fec2)
1--TEST--
2GH-15275 002: Crash during GC of suspended generator delegate
3--FILE--
4<?php
5
6class It implements \IteratorAggregate
7{
8    public function getIterator(): \Generator
9    {
10        yield 'foo';
11        try {
12            Fiber::suspend();
13        } finally {
14            var_dump(__METHOD__);
15        }
16        var_dump("not executed");
17    }
18}
19
20function f() {
21    try {
22        var_dump(new stdClass, yield from new It());
23    } finally {
24        var_dump(__FUNCTION__);
25    }
26}
27
28function g() {
29    try {
30        var_dump(new stdClass, yield from f());
31    } finally {
32        var_dump(__FUNCTION__);
33    }
34}
35
36$gen = g();
37
38$fiber = new Fiber(function () use ($gen) {
39    var_dump($gen->current());
40    $gen->next();
41    var_dump("not executed");
42});
43
44$ref = $fiber;
45
46$fiber->start();
47
48gc_collect_cycles();
49
50?>
51==DONE==
52--EXPECT--
53string(3) "foo"
54==DONE==
55string(15) "It::getIterator"
56string(1) "f"
57string(1) "g"
58