mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-11 16:49:43 +01:00
164 lines
5.0 KiB
Plaintext
164 lines
5.0 KiB
Plaintext
Array destructuring
|
|
-----
|
|
<?php
|
|
|
|
[$a, $b] = [$c, $d];
|
|
[, $a, , , $b, ,] = $foo;
|
|
[, [[$a]], $b] = $bar;
|
|
['a' => $b, 'b' => $a] = $baz;
|
|
-----
|
|
!!php7
|
|
array(
|
|
0: Stmt_Expression(
|
|
expr: Expr_Assign(
|
|
var: Expr_Array(
|
|
items: array(
|
|
0: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: a
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
1: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
)
|
|
)
|
|
expr: Expr_Array(
|
|
items: array(
|
|
0: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: c
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
1: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: d
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
)
|
|
)
|
|
)
|
|
)
|
|
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
|
|
unpack: false
|
|
)
|
|
2: null
|
|
3: null
|
|
4: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
5: null
|
|
)
|
|
)
|
|
expr: Expr_Variable(
|
|
name: foo
|
|
)
|
|
)
|
|
)
|
|
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
|
|
unpack: false
|
|
)
|
|
)
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
)
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
2: Expr_ArrayItem(
|
|
key: null
|
|
value: Expr_Variable(
|
|
name: b
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
)
|
|
)
|
|
expr: Expr_Variable(
|
|
name: bar
|
|
)
|
|
)
|
|
)
|
|
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
|
|
unpack: false
|
|
)
|
|
1: Expr_ArrayItem(
|
|
key: Scalar_String(
|
|
value: b
|
|
)
|
|
value: Expr_Variable(
|
|
name: a
|
|
)
|
|
byRef: false
|
|
unpack: false
|
|
)
|
|
)
|
|
)
|
|
expr: Expr_Variable(
|
|
name: baz
|
|
)
|
|
)
|
|
)
|
|
) |