xref: /PHP-Parser/test/code/parser/stmt/switch.test (revision 9a5d5c11)
1Switch
2-----
3<?php
4
5switch ($a) {
6    case 0:
7        break;
8    // Comment
9    case 1;
10    default:
11}
12
13// alternative syntax
14switch ($a):
15endswitch;
16
17// leading semicolon
18switch ($a) { ; }
19switch ($a): ; endswitch;
20-----
21array(
22    0: Stmt_Switch(
23        cond: Expr_Variable(
24            name: a
25        )
26        cases: array(
27            0: Stmt_Case(
28                cond: Scalar_Int(
29                    value: 0
30                )
31                stmts: array(
32                    0: Stmt_Break(
33                        num: null
34                    )
35                )
36            )
37            1: Stmt_Case(
38                cond: Scalar_Int(
39                    value: 1
40                )
41                stmts: array(
42                )
43                comments: array(
44                    0: // Comment
45                )
46            )
47            2: Stmt_Case(
48                cond: null
49                stmts: array(
50                )
51            )
52        )
53    )
54    1: Stmt_Switch(
55        cond: Expr_Variable(
56            name: a
57        )
58        cases: array(
59        )
60        comments: array(
61            0: // alternative syntax
62        )
63    )
64    2: Stmt_Switch(
65        cond: Expr_Variable(
66            name: a
67        )
68        cases: array(
69        )
70        comments: array(
71            0: // leading semicolon
72        )
73    )
74    3: Stmt_Switch(
75        cond: Expr_Variable(
76            name: a
77        )
78        cases: array(
79        )
80    )
81)
82