mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-02 17:38:19 +01:00
f8f1e17e41
Example: foreach ($coords as list($x, $y)) { ... } This change slightly breaks backwards compatability, as it changes the node structure for the previously existing `list(...) = $foo` assignments. Those no longer have a dedicated `AssignList` node; instead they are parsed as a normal `Assign` node with a `List` as `var`. Similarly the use in `foreach` will generate a `List` for `valueVar`.
139 lines
2.6 KiB
Plaintext
139 lines
2.6 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(
|
|
keyVar: null
|
|
byRef: false
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
)
|
|
1: Stmt_Foreach(
|
|
keyVar: null
|
|
byRef: true
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
)
|
|
2: Stmt_Foreach(
|
|
keyVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: false
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
valueVar: Expr_Variable(
|
|
name: c
|
|
)
|
|
)
|
|
3: Stmt_Foreach(
|
|
keyVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: true
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
valueVar: Expr_Variable(
|
|
name: c
|
|
)
|
|
)
|
|
4: Stmt_Foreach(
|
|
keyVar: null
|
|
byRef: false
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
valueVar: Expr_List(
|
|
vars: array(
|
|
0: Expr_Variable(
|
|
name: a
|
|
)
|
|
1: Expr_Variable(
|
|
name: b
|
|
)
|
|
)
|
|
)
|
|
)
|
|
5: Stmt_Foreach(
|
|
keyVar: Expr_Variable(
|
|
name: a
|
|
)
|
|
byRef: false
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
valueVar: Expr_List(
|
|
vars: array(
|
|
0: Expr_Variable(
|
|
name: b
|
|
)
|
|
1: null
|
|
2: Expr_Variable(
|
|
name: c
|
|
)
|
|
)
|
|
)
|
|
)
|
|
6: Stmt_Foreach(
|
|
keyVar: null
|
|
byRef: false
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Array(
|
|
items: array(
|
|
)
|
|
)
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
)
|
|
7: Stmt_Foreach(
|
|
keyVar: null
|
|
byRef: false
|
|
stmts: array(
|
|
)
|
|
expr: Expr_Variable(
|
|
name: a
|
|
)
|
|
valueVar: Expr_Variable(
|
|
name: b
|
|
)
|
|
)
|
|
) |