xref: /PHP-Parser/test/code/parser/stmt/if.test (revision 9a5d5c11)
1If/Elseif/Else
2-----
3<?php
4
5if      ($a) {}
6elseif  ($b) {}
7elseif  ($c) {}
8else         {}
9
10if ($a) {} // without else
11
12if      ($a):
13elseif  ($b):
14elseif  ($c):
15else        :
16endif;
17
18if ($a): endif; // without else
19-----
20array(
21    0: Stmt_If(
22        cond: Expr_Variable(
23            name: a
24        )
25        stmts: array(
26        )
27        elseifs: array(
28            0: Stmt_ElseIf(
29                cond: Expr_Variable(
30                    name: b
31                )
32                stmts: array(
33                )
34            )
35            1: Stmt_ElseIf(
36                cond: Expr_Variable(
37                    name: c
38                )
39                stmts: array(
40                )
41            )
42        )
43        else: Stmt_Else(
44            stmts: array(
45            )
46        )
47    )
48    1: Stmt_If(
49        cond: Expr_Variable(
50            name: a
51        )
52        stmts: array(
53        )
54        elseifs: array(
55        )
56        else: null
57    )
58    2: Stmt_If(
59        cond: Expr_Variable(
60            name: a
61        )
62        stmts: array(
63        )
64        elseifs: array(
65            0: Stmt_ElseIf(
66                cond: Expr_Variable(
67                    name: b
68                )
69                stmts: array(
70                )
71            )
72            1: Stmt_ElseIf(
73                cond: Expr_Variable(
74                    name: c
75                )
76                stmts: array(
77                )
78            )
79        )
80        else: Stmt_Else(
81            stmts: array(
82            )
83        )
84        comments: array(
85            0: // without else
86        )
87    )
88    3: Stmt_If(
89        cond: Expr_Variable(
90            name: a
91        )
92        stmts: array(
93        )
94        elseifs: array(
95        )
96        else: null
97    )
98    4: Stmt_Nop(
99        comments: array(
100            0: // without else
101        )
102    )
103)
104