xref: /PHP-7.4/Zend/tests/generators/bug71013.phpt (revision d679f022)
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 ()      { throw new Exception; }
10    function key ()          { return 0; }
11    function next ()         {}
12    function rewind ()       {}
13    function valid ()        { 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