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