summaryrefslogtreecommitdiff
path: root/Zend/tests/generators/bug71013.phpt
blob: 1b7bdd7935a6d68e7688f7dbb4a34a15f0bdd704 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--TEST--
Bug #71013 (Incorrect exception handler with yield from)
--FILE--
<?php

class FooBar implements Iterator {
    function __construct()   { echo "Constructing new FooBar\n"; }
    function __destruct()    { echo "Destructing FooBar\n"; }
    function current ()      { throw new Exception; }
    function key ()          { return 0; }
    function next ()         {}
    function rewind ()       {}
    function valid ()        { return true; }
}

function foo() {
    try {
        $f = new FooBar;
        yield from $f;
    } catch (Exception $e) {
        echo "[foo()] Caught Exception\n";
    }
}

function bar() {
    echo "Starting bar()\n";
    $x = foo();
    try {
        var_dump($x->current());
    } catch (Exception $e) {
        echo "[bar()] Caught Exception\n";
    }
    echo "Unsetting \$x\n";
    unset($x);
    echo "Finishing bar()\n";
}

bar();

?>
--EXPECT--
Starting bar()
Constructing new FooBar
[foo()] Caught Exception
Destructing FooBar
NULL
Unsetting $x
Finishing bar()