Skip to content

Commit 921b846

Browse files
committed
Support optional trailing comma in attribute argument list
1 parent 449b745 commit 921b846

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Trailing comma in attribute argument list
3+
--FILE--
4+
<?php
5+
6+
@@MyAttribute(
7+
"there",
8+
"are",
9+
"many",
10+
"arguments",
11+
)
12+
class Foo { }
13+
14+
$ref = new \ReflectionClass(Foo::class);
15+
$attr = $ref->getAttributes()[0];
16+
var_dump($attr->getName(), $attr->getArguments());
17+
18+
?>
19+
--EXPECT--
20+
string(11) "MyAttribute"
21+
array(4) {
22+
[0]=>
23+
string(5) "there"
24+
[1]=>
25+
string(3) "are"
26+
[2]=>
27+
string(4) "many"
28+
[3]=>
29+
string(9) "arguments"
30+
}

Zend/zend_language_parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ attribute:
330330
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); }
331331
| T_ATTRIBUTE '(' ')'
332332
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); }
333-
| T_ATTRIBUTE '(' attribute_arguments ')'
333+
| T_ATTRIBUTE '(' attribute_arguments possible_comma ')'
334334
{ $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, $3); }
335335
;
336336

0 commit comments

Comments
 (0)