static void zend_verify_list_assign_target(zend_ast *var_ast, zend_bool old_style) /* {{{ */ {
if (var_ast->kind == ZEND_AST_ARRAY) {
+ if (var_ast->attr == ZEND_ARRAY_SYNTAX_LONG) {
+ zend_error_noreturn(E_COMPILE_ERROR, "Cannot assign to array(), use [] instead");
+ }
if (old_style != var_ast->attr) {
- zend_error(E_COMPILE_ERROR, "Cannot mix [] and list()");
+ zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix [] and list()");
}
} else if (!zend_can_write_to_variable(var_ast)) {
- zend_error(E_COMPILE_ERROR, "Assignments can only happen to writable values");
+ zend_error_noreturn(E_COMPILE_ERROR, "Assignments can only happen to writable values");
}
}
/* }}} */
uint32_t i;
zend_bool is_constant = 1;
- if (ast->attr) {
+ if (ast->attr == ZEND_ARRAY_SYNTAX_LIST) {
zend_error(E_COMPILE_ERROR, "Cannot use list() as standalone expression");
}
foreach_variable:
variable { $$ = $1; }
| '&' variable { $$ = zend_ast_create(ZEND_AST_REF, $2); }
- | T_LIST '(' array_pair_list ')' { $3->attr = 1; $$ = $3; }
- | '[' array_pair_list ']' { $$ = $2; }
+ | T_LIST '(' array_pair_list ')' { $$ = $3; $$->attr = ZEND_ARRAY_SYNTAX_LIST; }
+ | '[' array_pair_list ']' { $$ = $2; $$->attr = ZEND_ARRAY_SYNTAX_SHORT; }
;
for_statement:
expr_without_variable:
T_LIST '(' array_pair_list ')' '=' expr
- { $3->attr = 1; $$ = zend_ast_create(ZEND_AST_ASSIGN, $3, $6); }
+ { $3->attr = ZEND_ARRAY_SYNTAX_LIST; $$ = zend_ast_create(ZEND_AST_ASSIGN, $3, $6); }
| '[' array_pair_list ']' '=' expr
- { $$ = zend_ast_create(ZEND_AST_ASSIGN, $2, $5); }
+ { $2->attr = ZEND_ARRAY_SYNTAX_SHORT; $$ = zend_ast_create(ZEND_AST_ASSIGN, $2, $5); }
| variable '=' expr
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
| variable '=' '&' variable
dereferencable_scalar:
- T_ARRAY '(' array_pair_list ')' { $$ = $3; }
- | '[' array_pair_list ']' { $$ = $2; }
+ T_ARRAY '(' array_pair_list ')' { $$ = $3; $$->attr = ZEND_ARRAY_SYNTAX_LONG; }
+ | '[' array_pair_list ']' { $$ = $2; $$->attr = ZEND_ARRAY_SYNTAX_SHORT; }
| T_CONSTANT_ENCAPSED_STRING { $$ = $1; }
;
| '&' variable
{ $$ = zend_ast_create_ex(ZEND_AST_ARRAY_ELEM, 1, $2, NULL); }
| expr T_DOUBLE_ARROW T_LIST '(' array_pair_list ')'
- { $5->attr = 1; $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $5, $1); }
+ { $5->attr = ZEND_ARRAY_SYNTAX_LIST;
+ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $5, $1); }
| T_LIST '(' array_pair_list ')'
- { $3->attr = 1; $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, NULL); }
+ { $3->attr = ZEND_ARRAY_SYNTAX_LIST;
+ $$ = zend_ast_create(ZEND_AST_ARRAY_ELEM, $3, NULL); }
;
encaps_list: