xref: /PHP-Parser/test/code/parser/expr/logic.test (revision 4e27a17c)
1Logical operators
2-----
3<?php
4
5// boolean ops
6$a && $b;
7$a || $b;
8!$a;
9!!$a;
10
11// logical ops
12$a and $b;
13$a or $b;
14$a xor $b;
15
16// precedence
17$a && $b || $c && $d;
18$a && ($b || $c) && $d;
19
20$a = $b || $c;
21$a = $b or $c;
22-----
23array(
24    0: Stmt_Expression(
25        expr: Expr_BinaryOp_BooleanAnd(
26            left: Expr_Variable(
27                name: a
28            )
29            right: Expr_Variable(
30                name: b
31            )
32        )
33        comments: array(
34            0: // boolean ops
35        )
36    )
37    1: Stmt_Expression(
38        expr: Expr_BinaryOp_BooleanOr(
39            left: Expr_Variable(
40                name: a
41            )
42            right: Expr_Variable(
43                name: b
44            )
45        )
46    )
47    2: Stmt_Expression(
48        expr: Expr_BooleanNot(
49            expr: Expr_Variable(
50                name: a
51            )
52        )
53    )
54    3: Stmt_Expression(
55        expr: Expr_BooleanNot(
56            expr: Expr_BooleanNot(
57                expr: Expr_Variable(
58                    name: a
59                )
60            )
61        )
62    )
63    4: Stmt_Expression(
64        expr: Expr_BinaryOp_LogicalAnd(
65            left: Expr_Variable(
66                name: a
67            )
68            right: Expr_Variable(
69                name: b
70            )
71        )
72        comments: array(
73            0: // logical ops
74        )
75    )
76    5: Stmt_Expression(
77        expr: Expr_BinaryOp_LogicalOr(
78            left: Expr_Variable(
79                name: a
80            )
81            right: Expr_Variable(
82                name: b
83            )
84        )
85    )
86    6: Stmt_Expression(
87        expr: Expr_BinaryOp_LogicalXor(
88            left: Expr_Variable(
89                name: a
90            )
91            right: Expr_Variable(
92                name: b
93            )
94        )
95    )
96    7: Stmt_Expression(
97        expr: Expr_BinaryOp_BooleanOr(
98            left: Expr_BinaryOp_BooleanAnd(
99                left: Expr_Variable(
100                    name: a
101                )
102                right: Expr_Variable(
103                    name: b
104                )
105            )
106            right: Expr_BinaryOp_BooleanAnd(
107                left: Expr_Variable(
108                    name: c
109                )
110                right: Expr_Variable(
111                    name: d
112                )
113            )
114        )
115        comments: array(
116            0: // precedence
117        )
118    )
119    8: Stmt_Expression(
120        expr: Expr_BinaryOp_BooleanAnd(
121            left: Expr_BinaryOp_BooleanAnd(
122                left: Expr_Variable(
123                    name: a
124                )
125                right: Expr_BinaryOp_BooleanOr(
126                    left: Expr_Variable(
127                        name: b
128                    )
129                    right: Expr_Variable(
130                        name: c
131                    )
132                )
133            )
134            right: Expr_Variable(
135                name: d
136            )
137        )
138    )
139    9: Stmt_Expression(
140        expr: Expr_Assign(
141            var: Expr_Variable(
142                name: a
143            )
144            expr: Expr_BinaryOp_BooleanOr(
145                left: Expr_Variable(
146                    name: b
147                )
148                right: Expr_Variable(
149                    name: c
150                )
151            )
152        )
153    )
154    10: Stmt_Expression(
155        expr: Expr_BinaryOp_LogicalOr(
156            left: Expr_Assign(
157                var: Expr_Variable(
158                    name: a
159                )
160                expr: Expr_Variable(
161                    name: b
162                )
163            )
164            right: Expr_Variable(
165                name: c
166            )
167        )
168    )
169)
170