Security update for Core, with self-updated composer
[yaffs-website] / vendor / nikic / php-parser / test / code / parser / stmt / generator / basic.test
1 Generators (yield expression)
2 -----
3 <?php
4
5 function gen() {
6     // statements
7     yield;
8     yield $value;
9     yield $key => $value;
10
11     // expressions
12     $data = yield;
13     $data = (yield $value);
14     $data = (yield $key => $value);
15
16     // yield in language constructs with their own parentheses
17     if (yield $foo); elseif (yield $foo);
18     if (yield $foo): elseif (yield $foo): endif;
19     while (yield $foo);
20     do {} while (yield $foo);
21     switch (yield $foo) {}
22     die(yield $foo);
23
24     // yield in function calls
25     func(yield $foo);
26     $foo->func(yield $foo);
27     new Foo(yield $foo);
28
29     yield from $foo;
30     yield from $foo and yield from $bar;
31     yield from $foo + $bar;
32 }
33 -----
34 array(
35     0: Stmt_Function(
36         byRef: false
37         name: gen
38         params: array(
39         )
40         returnType: null
41         stmts: array(
42             0: Expr_Yield(
43                 key: null
44                 value: null
45                 comments: array(
46                     0: // statements
47                 )
48             )
49             1: Expr_Yield(
50                 key: null
51                 value: Expr_Variable(
52                     name: value
53                 )
54             )
55             2: Expr_Yield(
56                 key: Expr_Variable(
57                     name: key
58                 )
59                 value: Expr_Variable(
60                     name: value
61                 )
62             )
63             3: Expr_Assign(
64                 var: Expr_Variable(
65                     name: data
66                     comments: array(
67                         0: // expressions
68                     )
69                 )
70                 expr: Expr_Yield(
71                     key: null
72                     value: null
73                 )
74                 comments: array(
75                     0: // expressions
76                 )
77             )
78             4: Expr_Assign(
79                 var: Expr_Variable(
80                     name: data
81                 )
82                 expr: Expr_Yield(
83                     key: null
84                     value: Expr_Variable(
85                         name: value
86                     )
87                 )
88             )
89             5: Expr_Assign(
90                 var: Expr_Variable(
91                     name: data
92                 )
93                 expr: Expr_Yield(
94                     key: Expr_Variable(
95                         name: key
96                     )
97                     value: Expr_Variable(
98                         name: value
99                     )
100                 )
101             )
102             6: Stmt_If(
103                 cond: Expr_Yield(
104                     key: null
105                     value: Expr_Variable(
106                         name: foo
107                     )
108                 )
109                 stmts: array(
110                 )
111                 elseifs: array(
112                     0: Stmt_ElseIf(
113                         cond: Expr_Yield(
114                             key: null
115                             value: Expr_Variable(
116                                 name: foo
117                             )
118                         )
119                         stmts: array(
120                         )
121                     )
122                 )
123                 else: null
124                 comments: array(
125                     0: // yield in language constructs with their own parentheses
126                 )
127             )
128             7: Stmt_If(
129                 cond: Expr_Yield(
130                     key: null
131                     value: Expr_Variable(
132                         name: foo
133                     )
134                 )
135                 stmts: array(
136                 )
137                 elseifs: array(
138                     0: Stmt_ElseIf(
139                         cond: Expr_Yield(
140                             key: null
141                             value: Expr_Variable(
142                                 name: foo
143                             )
144                         )
145                         stmts: array(
146                         )
147                     )
148                 )
149                 else: null
150             )
151             8: Stmt_While(
152                 cond: Expr_Yield(
153                     key: null
154                     value: Expr_Variable(
155                         name: foo
156                     )
157                 )
158                 stmts: array(
159                 )
160             )
161             9: Stmt_Do(
162                 cond: Expr_Yield(
163                     key: null
164                     value: Expr_Variable(
165                         name: foo
166                     )
167                 )
168                 stmts: array(
169                 )
170             )
171             10: Stmt_Switch(
172                 cond: Expr_Yield(
173                     key: null
174                     value: Expr_Variable(
175                         name: foo
176                     )
177                 )
178                 cases: array(
179                 )
180             )
181             11: Expr_Exit(
182                 expr: Expr_Yield(
183                     key: null
184                     value: Expr_Variable(
185                         name: foo
186                     )
187                 )
188             )
189             12: Expr_FuncCall(
190                 name: Name(
191                     parts: array(
192                         0: func
193                     )
194                     comments: array(
195                         0: // yield in function calls
196                     )
197                 )
198                 args: array(
199                     0: Arg(
200                         value: Expr_Yield(
201                             key: null
202                             value: Expr_Variable(
203                                 name: foo
204                             )
205                         )
206                         byRef: false
207                         unpack: false
208                     )
209                 )
210                 comments: array(
211                     0: // yield in function calls
212                 )
213             )
214             13: Expr_MethodCall(
215                 var: Expr_Variable(
216                     name: foo
217                 )
218                 name: func
219                 args: array(
220                     0: Arg(
221                         value: Expr_Yield(
222                             key: null
223                             value: Expr_Variable(
224                                 name: foo
225                             )
226                         )
227                         byRef: false
228                         unpack: false
229                     )
230                 )
231             )
232             14: Expr_New(
233                 class: Name(
234                     parts: array(
235                         0: Foo
236                     )
237                 )
238                 args: array(
239                     0: Arg(
240                         value: Expr_Yield(
241                             key: null
242                             value: Expr_Variable(
243                                 name: foo
244                             )
245                         )
246                         byRef: false
247                         unpack: false
248                     )
249                 )
250             )
251             15: Expr_YieldFrom(
252                 expr: Expr_Variable(
253                     name: foo
254                 )
255             )
256             16: Expr_BinaryOp_LogicalAnd(
257                 left: Expr_YieldFrom(
258                     expr: Expr_Variable(
259                         name: foo
260                     )
261                 )
262                 right: Expr_YieldFrom(
263                     expr: Expr_Variable(
264                         name: bar
265                     )
266                 )
267             )
268             17: Expr_YieldFrom(
269                 expr: Expr_BinaryOp_Plus(
270                     left: Expr_Variable(
271                         name: foo
272                     )
273                     right: Expr_Variable(
274                         name: bar
275                     )
276                 )
277             )
278         )
279     )
280 )