1Generators (yield expression) 2----- 3<?php 4 5function 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----- 34array( 35 0: Stmt_Function( 36 attrGroups: array( 37 ) 38 byRef: false 39 name: Identifier( 40 name: gen 41 ) 42 params: array( 43 ) 44 returnType: null 45 stmts: array( 46 0: Stmt_Expression( 47 expr: Expr_Yield( 48 key: null 49 value: null 50 ) 51 comments: array( 52 0: // statements 53 ) 54 ) 55 1: Stmt_Expression( 56 expr: Expr_Yield( 57 key: null 58 value: Expr_Variable( 59 name: value 60 ) 61 ) 62 ) 63 2: Stmt_Expression( 64 expr: Expr_Yield( 65 key: Expr_Variable( 66 name: key 67 ) 68 value: Expr_Variable( 69 name: value 70 ) 71 ) 72 ) 73 3: Stmt_Expression( 74 expr: Expr_Assign( 75 var: Expr_Variable( 76 name: data 77 ) 78 expr: Expr_Yield( 79 key: null 80 value: null 81 ) 82 ) 83 comments: array( 84 0: // expressions 85 ) 86 ) 87 4: Stmt_Expression( 88 expr: Expr_Assign( 89 var: Expr_Variable( 90 name: data 91 ) 92 expr: Expr_Yield( 93 key: null 94 value: Expr_Variable( 95 name: value 96 ) 97 ) 98 ) 99 ) 100 5: Stmt_Expression( 101 expr: Expr_Assign( 102 var: Expr_Variable( 103 name: data 104 ) 105 expr: Expr_Yield( 106 key: Expr_Variable( 107 name: key 108 ) 109 value: Expr_Variable( 110 name: value 111 ) 112 ) 113 ) 114 ) 115 6: Stmt_If( 116 cond: Expr_Yield( 117 key: null 118 value: Expr_Variable( 119 name: foo 120 ) 121 ) 122 stmts: array( 123 ) 124 elseifs: array( 125 0: Stmt_ElseIf( 126 cond: Expr_Yield( 127 key: null 128 value: Expr_Variable( 129 name: foo 130 ) 131 ) 132 stmts: array( 133 ) 134 ) 135 ) 136 else: null 137 comments: array( 138 0: // yield in language constructs with their own parentheses 139 ) 140 ) 141 7: Stmt_If( 142 cond: Expr_Yield( 143 key: null 144 value: Expr_Variable( 145 name: foo 146 ) 147 ) 148 stmts: array( 149 ) 150 elseifs: array( 151 0: Stmt_ElseIf( 152 cond: Expr_Yield( 153 key: null 154 value: Expr_Variable( 155 name: foo 156 ) 157 ) 158 stmts: array( 159 ) 160 ) 161 ) 162 else: null 163 ) 164 8: Stmt_While( 165 cond: Expr_Yield( 166 key: null 167 value: Expr_Variable( 168 name: foo 169 ) 170 ) 171 stmts: array( 172 ) 173 ) 174 9: Stmt_Do( 175 stmts: array( 176 ) 177 cond: Expr_Yield( 178 key: null 179 value: Expr_Variable( 180 name: foo 181 ) 182 ) 183 ) 184 10: Stmt_Switch( 185 cond: Expr_Yield( 186 key: null 187 value: Expr_Variable( 188 name: foo 189 ) 190 ) 191 cases: array( 192 ) 193 ) 194 11: Stmt_Expression( 195 expr: Expr_Exit( 196 expr: Expr_Yield( 197 key: null 198 value: Expr_Variable( 199 name: foo 200 ) 201 ) 202 ) 203 ) 204 12: Stmt_Expression( 205 expr: Expr_FuncCall( 206 name: Name( 207 name: func 208 ) 209 args: array( 210 0: Arg( 211 name: null 212 value: Expr_Yield( 213 key: null 214 value: Expr_Variable( 215 name: foo 216 ) 217 ) 218 byRef: false 219 unpack: false 220 ) 221 ) 222 ) 223 comments: array( 224 0: // yield in function calls 225 ) 226 ) 227 13: Stmt_Expression( 228 expr: Expr_MethodCall( 229 var: Expr_Variable( 230 name: foo 231 ) 232 name: Identifier( 233 name: func 234 ) 235 args: array( 236 0: Arg( 237 name: null 238 value: Expr_Yield( 239 key: null 240 value: Expr_Variable( 241 name: foo 242 ) 243 ) 244 byRef: false 245 unpack: false 246 ) 247 ) 248 ) 249 ) 250 14: Stmt_Expression( 251 expr: Expr_New( 252 class: Name( 253 name: Foo 254 ) 255 args: array( 256 0: Arg( 257 name: null 258 value: Expr_Yield( 259 key: null 260 value: Expr_Variable( 261 name: foo 262 ) 263 ) 264 byRef: false 265 unpack: false 266 ) 267 ) 268 ) 269 ) 270 15: Stmt_Expression( 271 expr: Expr_YieldFrom( 272 expr: Expr_Variable( 273 name: foo 274 ) 275 ) 276 ) 277 16: Stmt_Expression( 278 expr: Expr_BinaryOp_LogicalAnd( 279 left: Expr_YieldFrom( 280 expr: Expr_Variable( 281 name: foo 282 ) 283 ) 284 right: Expr_YieldFrom( 285 expr: Expr_Variable( 286 name: bar 287 ) 288 ) 289 ) 290 ) 291 17: Stmt_Expression( 292 expr: Expr_YieldFrom( 293 expr: Expr_BinaryOp_Plus( 294 left: Expr_Variable( 295 name: foo 296 ) 297 right: Expr_Variable( 298 name: bar 299 ) 300 ) 301 ) 302 ) 303 ) 304 ) 305) 306