xref: /PHP-8.3/Zend/tests/gh15866.phpt (revision 6e55f4df)
1--TEST--
2GH-15866: Core dumped in Zend/zend_generators.c
3--FILE--
4<?php
5
6class Canary {
7    public function __construct(public mixed $value) {}
8    public function __destruct() {
9        printf("%s\n", __METHOD__);
10    }
11}
12
13function g() {
14    Fiber::suspend();
15}
16
17function f($canary) {
18    try {
19        var_dump(yield from g());
20    } finally {
21        print "Generator finally\n";
22    }
23}
24
25$canary = new Canary(null);
26$iterable = f($canary);
27$fiber = new Fiber(function () use ($iterable, $canary) {
28    try {
29        $iterable->next();
30    } finally {
31        print "Fiber finally\n";
32    }
33});
34$canary->value = $fiber;
35$fiber->start();
36
37// Reset roots
38gc_collect_cycles();
39
40// Add to roots, create garbage cycles
41$fiber = $iterable = $canary = null;
42
43print "Collect cycles\n";
44gc_collect_cycles();
45
46?>
47==DONE==
48--EXPECT--
49Collect cycles
50Canary::__destruct
51Generator finally
52Fiber finally
53==DONE==
54