mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-12-11 08:59:46 +01:00
574665b45b
Expr\List will now contain ArrayItems instead of plain variables. I'm reusing ArrayItem, because code handling list() must also handle arrays, and this allows both to go through the same code path. This also renames Expr\List->vars to ->items. TODO: Should Expr\List be dropped in favor of Expr\Array with an extra flag?
164 lines
3.3 KiB
Plaintext
164 lines
3.3 KiB
Plaintext
Foreach loop
|
|
-----
|
|
<?php
|
|
|
|
// foreach on variable
|
|
foreach ($a as $b) {}
|
|
foreach ($a as &$b) {}
|
|
foreach ($a as $b => $c) {}
|
|
foreach ($a as $b => &$c) {}
|
|
foreach ($a as list($a, $b)) {}
|
|
foreach ($a as $a => list($b, , $c)) {}
|
|
|
|
// foreach on expression
|
|
foreach (array() as $b) {}
|
|
|
|
// alternative syntax
|
|
foreach ($a as $b):
|
|
endforeach;
|
|
-----
|
|
array(
|
|
0: Stmt_Foreach(
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
keyVar: null
|
|
byRef: false
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
stmts: array(
|
|
)
|
|
comments: array(
|
|
0: // foreach on variable
|
|
)
|
|
)
|
|
1: Stmt_Foreach(
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
keyVar: null
|
|
byRef: true
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
stmts: array(
|
|
)
|
|
)
|
|
2: Stmt_Foreach(
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
keyVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: false
|
|
valueVar: Expr_Variable(
|
|
name: c
|
|
)
|
|
stmts: array(
|
|
)
|
|
)
|
|
3: Stmt_Foreach(
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
keyVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: true
|
|
valueVar: Expr_Variable(
|
|
name: c
|
|
)
|
|
stmts: array(
|
|
)
|
|
)
|
|
4: Stmt_Foreach(
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
keyVar: null
|
|
byRef: false
|
|
valueVar: Expr_List(
|
|
items: array(
|
|
0: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: a
|
|
)
|
|
byRef: false
|
|
)
|
|
1: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: false
|
|
)
|
|
)
|
|
)
|
|
stmts: array(
|
|
)
|
|
)
|
|
5: Stmt_Foreach(
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
keyVar: Expr_Variable(
|
|
name: a
|
|
)
|
|
byRef: false
|
|
valueVar: Expr_List(
|
|
items: array(
|
|
0: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: false
|
|
)
|
|
1: null
|
|
2: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: c
|
|
)
|
|
byRef: false
|
|
)
|
|
)
|
|
)
|
|
stmts: array(
|
|
)
|
|
)
|
|
6: Stmt_Foreach(
|
|
expr: Expr_Array(
|
|
items: array(
|
|
)
|
|
)
|
|
keyVar: null
|
|
byRef: false
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
stmts: array(
|
|
)
|
|
comments: array(
|
|
0: // foreach on expression
|
|
)
|
|
)
|
|
7: Stmt_Foreach(
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
keyVar: null
|
|
byRef: false
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
stmts: array(
|
|
)
|
|
comments: array(
|
|
0: // alternative syntax
|
|
)
|
|
)
|
|
) |