xref: /PHP-8.1/Zend/tests/generators/bug71013.phpt (revision 75a678a7)
1--TEST--
2Bug #71013 (Incorrect exception handler with yield from)
3--FILE--
4<?php
5
6class FooBar implements Iterator {
7    function __construct()   { echo "Constructing new FooBar\n"; }
8    function __destruct()    { echo "Destructing FooBar\n"; }
9    function current (): mixed      { throw new Exception; }
10    function key (): int          { return 0; }
11    function next (): void         {}
12    function rewind (): void       {}
13    function valid (): bool        { return true; }
14}
15
16function foo() {
17    try {
18        $f = new FooBar;
19        yield from $f;
20    } catch (Exception $e) {
21        echo "[foo()] Caught Exception\n";
22    }
23}
24
25function bar() {
26    echo "Starting bar()\n";
27    $x = foo();
28    try {
29        var_dump($x->current());
30    } catch (Exception $e) {
31        echo "[bar()] Caught Exception\n";
32    }
33    echo "Unsetting \$x\n";
34    unset($x);
35    echo "Finishing bar()\n";
36}
37
38bar();
39
40?>
41--EXPECT--
42Starting bar()
43Constructing new FooBar
44[foo()] Caught Exception
45Destructing FooBar
46NULL
47Unsetting $x
48Finishing bar()
49