xref: /PHP-Parser/test/code/parser/stmt/tryCatch.test (revision 23647573)
1Try/catch
2-----
3<?php
4
5try {
6    doTry();
7} catch (A $b) {
8    doCatchA();
9} catch (B $c) {
10    doCatchB();
11} finally {
12    doFinally();
13}
14
15// no finally
16try { }
17catch (A $b) { }
18
19// no catch
20try { }
21finally { }
22
23-----
24array(
25    0: Stmt_TryCatch(
26        stmts: array(
27            0: Stmt_Expression(
28                expr: Expr_FuncCall(
29                    name: Name(
30                        name: doTry
31                    )
32                    args: array(
33                    )
34                )
35            )
36        )
37        catches: array(
38            0: Stmt_Catch(
39                types: array(
40                    0: Name(
41                        name: A
42                    )
43                )
44                var: Expr_Variable(
45                    name: b
46                )
47                stmts: array(
48                    0: Stmt_Expression(
49                        expr: Expr_FuncCall(
50                            name: Name(
51                                name: doCatchA
52                            )
53                            args: array(
54                            )
55                        )
56                    )
57                )
58            )
59            1: Stmt_Catch(
60                types: array(
61                    0: Name(
62                        name: B
63                    )
64                )
65                var: Expr_Variable(
66                    name: c
67                )
68                stmts: array(
69                    0: Stmt_Expression(
70                        expr: Expr_FuncCall(
71                            name: Name(
72                                name: doCatchB
73                            )
74                            args: array(
75                            )
76                        )
77                    )
78                )
79            )
80        )
81        finally: Stmt_Finally(
82            stmts: array(
83                0: Stmt_Expression(
84                    expr: Expr_FuncCall(
85                        name: Name(
86                            name: doFinally
87                        )
88                        args: array(
89                        )
90                    )
91                )
92            )
93        )
94    )
95    1: Stmt_TryCatch(
96        stmts: array(
97        )
98        catches: array(
99            0: Stmt_Catch(
100                types: array(
101                    0: Name(
102                        name: A
103                    )
104                )
105                var: Expr_Variable(
106                    name: b
107                )
108                stmts: array(
109                )
110            )
111        )
112        finally: null
113        comments: array(
114            0: // no finally
115        )
116    )
117    2: Stmt_TryCatch(
118        stmts: array(
119        )
120        catches: array(
121        )
122        finally: Stmt_Finally(
123            stmts: array(
124            )
125        )
126        comments: array(
127            0: // no catch
128        )
129    )
130)
131