1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-12-03 09:47:59 +01:00
PHP-Parser/test/code/parser/stmt/loop/foreach.test

168 lines
3.4 KiB
Plaintext
Raw Normal View History

2011-11-27 11:20:35 +01:00
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)) {}
2011-11-27 11:20:35 +01:00
// 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
2011-11-27 11:20:35 +01:00
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
comments: array(
0: // foreach on variable
)
)
1: Stmt_Foreach(
2011-11-27 11:20:35 +01:00
expr: Expr_Variable(
name: a
)
keyVar: null
byRef: true
2011-11-27 11:20:35 +01:00
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
2011-11-27 11:20:35 +01:00
)
2: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
2011-11-27 11:20:35 +01:00
keyVar: Expr_Variable(
name: b
)
byRef: false
valueVar: Expr_Variable(
name: c
)
stmts: array(
)
2011-11-27 11:20:35 +01:00
)
3: Stmt_Foreach(
expr: Expr_Variable(
name: a
)
2011-11-27 11:20:35 +01:00
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
2019-05-09 15:11:00 +02:00
unpack: false
)
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: false
2019-05-09 15:11:00 +02:00
unpack: 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
2019-05-09 15:11:00 +02:00
unpack: false
)
1: null
2: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: c
)
byRef: false
2019-05-09 15:11:00 +02:00
unpack: false
)
)
)
2011-11-27 11:20:35 +01:00
stmts: array(
)
)
6: Stmt_Foreach(
2011-11-27 11:20:35 +01:00
expr: Expr_Array(
items: array(
)
)
keyVar: null
byRef: false
2011-11-27 11:20:35 +01:00
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
comments: array(
0: // foreach on expression
)
)
7: Stmt_Foreach(
2011-11-27 11:20:35 +01:00
expr: Expr_Variable(
name: a
)
keyVar: null
byRef: false
2011-11-27 11:20:35 +01:00
valueVar: Expr_Variable(
name: b
)
stmts: array(
)
comments: array(
0: // alternative syntax
)
2011-11-27 11:20:35 +01:00
)
)