Skip to content

Commit f545ee2

Browse files
committed
Allow optional trailing comma in parameter list
RFC: https://wiki.php.net/rfc/trailing_comma_in_parameter_list Closes GH-5306.
1 parent 5eb4ab0 commit f545ee2

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ PHP 8.0 UPGRADE NOTES
462462
RFC: https://wiki.php.net/rfc/abstract_trait_method_validation
463463
. `throw` can now be used as an expression.
464464
RFC: https://wiki.php.net/rfc/throw_expression
465+
. An optional trailing comma is now allowed in parameter lists.
466+
RFC: https://wiki.php.net/rfc/trailing_comma_in_parameter_list
465467

466468
- Date:
467469
. Added DateTime::createFromInterface() and
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
--TEST--
2+
Trailing comma in function signatures
3+
--FILE--
4+
<?php
5+
6+
function test(
7+
$there,
8+
$are,
9+
$many,
10+
$params,
11+
) {
12+
echo "Foo\n";
13+
}
14+
15+
class Test {
16+
public function method(
17+
$there,
18+
$are,
19+
$many,
20+
$params,
21+
) {
22+
echo "Foo\n";
23+
}
24+
}
25+
26+
$func = function(
27+
$there,
28+
$are,
29+
$many,
30+
$params,
31+
) {
32+
echo "Foo\n";
33+
};
34+
35+
$func = fn(
36+
$there,
37+
$shouldnt,
38+
$be,
39+
$many,
40+
$params,
41+
) => print "Foo\n";
42+
43+
?>
44+
===DONE===
45+
--EXPECT--
46+
===DONE===

Zend/zend_language_parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ alt_if_stmt:
633633
;
634634

635635
parameter_list:
636-
non_empty_parameter_list { $$ = $1; }
636+
non_empty_parameter_list possible_comma { $$ = $1; }
637637
| %empty { $$ = zend_ast_create_list(0, ZEND_AST_PARAM_LIST); }
638638
;
639639

0 commit comments

Comments
 (0)