xref: /php-src/Zend/tests/try/try_finally_020.phpt (revision f8d79582)
1--TEST--
2Combination of foreach, finally and exception (call order)
3--FILE--
4<?php
5class A {
6    public $n = 0;
7    function __construct($n) {
8        $this->n = $n;
9    }
10    function __destruct() {
11        echo "destruct" . $this->n . "\n";
12    }
13}
14
15foreach ([new A(1)] as $a) {
16    $a = null;
17    try {
18        foreach ([new A(2)] as $a) {
19            $a = null;
20            try {
21                foreach ([new A(3)] as $a) {
22                    $a = null;
23                    throw new Exception();
24                }
25            } finally {
26                echo "finally1\n";
27            }
28        }
29    } catch (Exception $e) {
30        echo "catch\n";
31    } finally {
32        echo "finally2\n";
33    }
34}
35?>
36--EXPECT--
37destruct3
38finally1
39destruct2
40catch
41finally2
42destruct1
43