xref: /PHP-8.3/Zend/tests/gh15330-006.phpt (revision cd255007)
1--TEST--
2GH-15330 006: 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 h() {
14    yield 'foo';
15    Fiber::suspend();
16}
17
18function g() {
19    yield from h();
20}
21
22function f($canary) {
23    var_dump(yield from g());
24}
25
26$canary = new Canary(null);
27
28$iterable = f($canary);
29
30$fiber = new Fiber(function () use ($iterable, $canary) {
31    var_dump($canary, $iterable->current());
32    $iterable->next();
33    var_dump("not executed");
34});
35
36$canary->value = $fiber;
37
38$fiber->start();
39
40$iterable->current();
41
42$fiber = $iterable = $canary = null;
43
44gc_collect_cycles();
45
46?>
47==DONE==
48--EXPECTF--
49object(Canary)#%d (1) {
50  ["value"]=>
51  object(Fiber)#%d (0) {
52  }
53}
54string(3) "foo"
55string(18) "Canary::__destruct"
56==DONE==
57