xref: /PHP-8.0/Zend/tests/bug71980.phpt (revision aad4eceb)
1--TEST--
2Bug #71980: Decorated/Nested Generator is Uncloseable in Finally
3--FILE--
4<?php
5
6class Dtor {
7    public function __destruct() {
8        echo "Dtor\n";
9    }
10}
11
12function gen1() {
13    try {
14        foreach ([42, new Dtor] as $value) {
15            yield $value;
16        }
17    } finally {
18        echo "Finally\n";
19    }
20}
21
22function gen2() {
23    try {
24        var_dump(new Dtor, yield);
25    } finally {
26        echo "Finally\n";
27    }
28}
29
30$gen = gen1();
31$gen->rewind();
32unset($gen);
33
34$gen = gen2();
35$gen->rewind();
36unset($gen);
37
38?>
39--EXPECT--
40Dtor
41Finally
42Dtor
43Finally
44