xref: /PHP-8.4/Zend/tests/gh15330-005.phpt (revision cd255007)
1--TEST--
2GH-15330 005: Do not scan generator frames more than once
3--FILE--
4<?php
5
6class Canary {
7    public function __construct(public mixed $value) {}
8    public function __destruct() {
9        var_dump(__METHOD__);
10    }
11}
12
13function g() {
14    yield 'foo';
15    Fiber::suspend();
16}
17
18function f($canary) {
19    var_dump(yield from g());
20}
21
22$canary = new Canary(null);
23
24$iterable = f($canary);
25
26$fiber = new Fiber(function () use ($iterable, $canary) {
27    var_dump($canary, $iterable->current());
28    $f = $iterable->next(...);
29    $f();
30    var_dump("not executed");
31});
32
33$canary->value = $fiber;
34
35$fiber->start();
36
37$iterable->current();
38
39$fiber = $iterable = $canary = null;
40
41gc_collect_cycles();
42
43?>
44==DONE==
45--EXPECTF--
46object(Canary)#%d (1) {
47  ["value"]=>
48  object(Fiber)#%d (0) {
49  }
50}
51string(3) "foo"
52string(18) "Canary::__destruct"
53==DONE==
54