2016-07-06 23:21:53 +02:00
|
|
|
Array destructuring
|
|
|
|
-----
|
|
|
|
<?php
|
|
|
|
|
|
|
|
[$a, $b] = [$c, $d];
|
|
|
|
[, $a, , , $b, ,] = $foo;
|
|
|
|
[, [[$a]], $b] = $bar;
|
|
|
|
['a' => $b, 'b' => $a] = $baz;
|
|
|
|
-----
|
|
|
|
!!php7
|
|
|
|
array(
|
2017-01-19 22:25:22 +01:00
|
|
|
0: Stmt_Expression(
|
|
|
|
expr: Expr_Assign(
|
|
|
|
var: Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
1: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
expr: Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: c
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
1: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: d
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
1: Stmt_Expression(
|
|
|
|
expr: Expr_Assign(
|
|
|
|
var: Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: null
|
|
|
|
1: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
2: null
|
|
|
|
3: null
|
|
|
|
4: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
5: null
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
expr: Expr_Variable(
|
|
|
|
name: foo
|
|
|
|
)
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
2: Stmt_Expression(
|
|
|
|
expr: Expr_Assign(
|
|
|
|
var: Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: null
|
|
|
|
1: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
2: Expr_ArrayItem(
|
|
|
|
key: null
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
expr: Expr_Variable(
|
|
|
|
name: bar
|
|
|
|
)
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
3: Stmt_Expression(
|
|
|
|
expr: Expr_Assign(
|
|
|
|
var: Expr_Array(
|
|
|
|
items: array(
|
|
|
|
0: Expr_ArrayItem(
|
|
|
|
key: Scalar_String(
|
|
|
|
value: a
|
|
|
|
)
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: b
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
1: Expr_ArrayItem(
|
|
|
|
key: Scalar_String(
|
|
|
|
value: b
|
|
|
|
)
|
|
|
|
value: Expr_Variable(
|
|
|
|
name: a
|
|
|
|
)
|
|
|
|
byRef: false
|
2019-05-09 15:11:00 +02:00
|
|
|
unpack: false
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-01-19 22:25:22 +01:00
|
|
|
expr: Expr_Variable(
|
|
|
|
name: baz
|
|
|
|
)
|
2016-07-06 23:21:53 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|