--- /dev/null
+--TEST--
+Cannot use unpacking in attribute argument list
+--FILE--
+<?php
+
+<<MyAttribute(...[1, 2, 3])>>
+class Foo { }
+
+?>
+--EXPECTF--
+Fatal error: Cannot use unpacking in attribute argument list in %s on line %d
--- /dev/null
+--TEST--
+Trailing comma in attribute argument list
+--FILE--
+<?php
+
+<<MyAttribute(
+ "there",
+ "are",
+ "many",
+ "arguments",
+)>>
+class Foo { }
+
+$ref = new \ReflectionClass(Foo::class);
+$attr = $ref->getAttributes()[0];
+var_dump($attr->getName(), $attr->getArguments());
+
+?>
+--EXPECT--
+string(11) "MyAttribute"
+array(4) {
+ [0]=>
+ string(5) "there"
+ [1]=>
+ string(3) "are"
+ [2]=>
+ string(4) "many"
+ [3]=>
+ string(9) "arguments"
+}
?>
--EXPECTF--
-Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ';' in %s on line %d
+Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ';' or ',' in %s on line %d
ZEND_ASSERT(args->kind == ZEND_AST_ARG_LIST);
for (j = 0; j < args->children; j++) {
+ if (args->child[j]->kind == ZEND_AST_UNPACK) {
+ zend_error_noreturn(E_COMPILE_ERROR,
+ "Cannot use unpacking in attribute argument list");
+ }
+
zend_const_expr_to_zval(&attr->argv[j], args->child[j]);
}
}
%type <ast> identifier type_expr_without_static union_type_without_static
%type <ast> inline_function union_type
%type <ast> attributed_statement attributed_class_statement attributed_parameter
-%type <ast> attribute_arguments attribute_decl attribute attributes
+%type <ast> attribute_decl attribute attributes
%type <num> returns_ref function fn is_reference is_variadic variable_modifiers
%type <num> method_modifiers non_empty_member_modifiers member_modifier optional_visibility_modifier
| T_NS_SEPARATOR namespace_name { $$ = $2; $$->attr = ZEND_NAME_FQ; }
;
-attribute_arguments:
- expr
- { $$ = zend_ast_create_list(1, ZEND_AST_ARG_LIST, $1); }
- | attribute_arguments ',' expr
- { $$ = zend_ast_list_add($1, $3); }
-;
-
attribute_decl:
class_name
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); }
- | class_name '(' ')'
- { $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); }
- | class_name '(' attribute_arguments ')'
- { $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, $3); }
+ | class_name argument_list
+ { $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, $2); }
;
attribute: