summaryrefslogtreecommitdiff
path: root/Zend/tests/generators/iterator_wrapper_leak.phpt
blob: bc0f34e9c8d4b6a984bd77ca545284e1c484d439 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
--TEST--
A generator iterator wrapper involved in a cycle should not leak
--FILE--
<?php

class Test {
    public function method() {
        $this->gen1 = (function () {
            yield 1;
            yield 2;
            yield 3;
        })();
        $gen2 = function() {
            foreach ($this->gen1 as $x) {
                echo "$x\n";
                yield $x;
            }
        };
        $this->gen2 = $gen2();
        foreach ($this->gen2 as $x) {
            if ($x == 2) {
                break;
            }
        }
    }
}
(new Test)->method();
gc_collect_cycles();

?>
--EXPECT--
1
2