mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-26 20:14:46 +01:00
Add support for list reference assignments
RFC: https://wiki.php.net/rfc/list_reference_assignment
This commit is contained in:
parent
91a462ce76
commit
7f8ff1b9a4
@ -4,6 +4,7 @@ Version 4.0.1-dev
|
||||
### Added
|
||||
|
||||
* [PHP 7.3] Added support for trailing commas in function calls.
|
||||
* [PHP 7.3] Added support for by-reference array destructuring.
|
||||
* Added checks to node traverser to prevent replacing a statement with an expression or vice versa.
|
||||
This should prevent common mistakes in the implementation of node visitors.
|
||||
* Added the following method to `BuilderFactory`, to simplify creation of expressions:
|
||||
|
@ -929,8 +929,10 @@ list_expr_elements:
|
||||
|
||||
list_expr_element:
|
||||
variable { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| '&' variable { $$ = Expr\ArrayItem[$2, null, true]; }
|
||||
| list_expr { $$ = Expr\ArrayItem[$1, null, false]; }
|
||||
| expr T_DOUBLE_ARROW variable { $$ = Expr\ArrayItem[$3, $1, false]; }
|
||||
| expr T_DOUBLE_ARROW '&' variable { $$ = Expr\ArrayItem[$4, $1, true]; }
|
||||
| expr T_DOUBLE_ARROW list_expr { $$ = Expr\ArrayItem[$3, $1, false]; }
|
||||
| /* empty */ { $$ = null; }
|
||||
;
|
||||
|
File diff suppressed because it is too large
Load Diff
88
test/code/parser/expr/listReferences.test
Normal file
88
test/code/parser/expr/listReferences.test
Normal file
@ -0,0 +1,88 @@
|
||||
List reference assignments (PHP 7.3)
|
||||
-----
|
||||
<?php
|
||||
|
||||
list(&$v) = $x;
|
||||
list('k' => &$v) = $x;
|
||||
[&$v] = $x;
|
||||
['k' => &$v] = $x;
|
||||
-----
|
||||
!!php7
|
||||
array(
|
||||
0: Stmt_Expression(
|
||||
expr: Expr_Assign(
|
||||
var: Expr_List(
|
||||
items: array(
|
||||
0: Expr_ArrayItem(
|
||||
key: null
|
||||
value: Expr_Variable(
|
||||
name: v
|
||||
)
|
||||
byRef: true
|
||||
)
|
||||
)
|
||||
)
|
||||
expr: Expr_Variable(
|
||||
name: x
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_Expression(
|
||||
expr: Expr_Assign(
|
||||
var: Expr_List(
|
||||
items: array(
|
||||
0: Expr_ArrayItem(
|
||||
key: Scalar_String(
|
||||
value: k
|
||||
)
|
||||
value: Expr_Variable(
|
||||
name: v
|
||||
)
|
||||
byRef: true
|
||||
)
|
||||
)
|
||||
)
|
||||
expr: Expr_Variable(
|
||||
name: x
|
||||
)
|
||||
)
|
||||
)
|
||||
2: Stmt_Expression(
|
||||
expr: Expr_Assign(
|
||||
var: Expr_Array(
|
||||
items: array(
|
||||
0: Expr_ArrayItem(
|
||||
key: null
|
||||
value: Expr_Variable(
|
||||
name: v
|
||||
)
|
||||
byRef: true
|
||||
)
|
||||
)
|
||||
)
|
||||
expr: Expr_Variable(
|
||||
name: x
|
||||
)
|
||||
)
|
||||
)
|
||||
3: Stmt_Expression(
|
||||
expr: Expr_Assign(
|
||||
var: Expr_Array(
|
||||
items: array(
|
||||
0: Expr_ArrayItem(
|
||||
key: Scalar_String(
|
||||
value: k
|
||||
)
|
||||
value: Expr_Variable(
|
||||
name: v
|
||||
)
|
||||
byRef: true
|
||||
)
|
||||
)
|
||||
)
|
||||
expr: Expr_Variable(
|
||||
name: x
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
Loading…
Reference in New Issue
Block a user