Allow optional trailing comma in parameter list

RFC: https://wiki.php.net/rfc/trailing_comma_in_parameter_list

Closes GH-5306.
This commit is contained in:
Nikita Popov 2020-03-26 16:39:08 +01:00
parent 5eb4ab07f2
commit f545ee2c6c
3 changed files with 49 additions and 1 deletions

View file

@ -462,6 +462,8 @@ PHP 8.0 UPGRADE NOTES
RFC: https://wiki.php.net/rfc/abstract_trait_method_validation
. `throw` can now be used as an expression.
RFC: https://wiki.php.net/rfc/throw_expression
. An optional trailing comma is now allowed in parameter lists.
RFC: https://wiki.php.net/rfc/trailing_comma_in_parameter_list
- Date:
. Added DateTime::createFromInterface() and

View file

@ -0,0 +1,46 @@
--TEST--
Trailing comma in function signatures
--FILE--
<?php
function test(
$there,
$are,
$many,
$params,
) {
echo "Foo\n";
}
class Test {
public function method(
$there,
$are,
$many,
$params,
) {
echo "Foo\n";
}
}
$func = function(
$there,
$are,
$many,
$params,
) {
echo "Foo\n";
};
$func = fn(
$there,
$shouldnt,
$be,
$many,
$params,
) => print "Foo\n";
?>
===DONE===
--EXPECT--
===DONE===

View file

@ -633,7 +633,7 @@ alt_if_stmt:
;
parameter_list:
non_empty_parameter_list { $$ = $1; }
non_empty_parameter_list possible_comma { $$ = $1; }
| %empty { $$ = zend_ast_create_list(0, ZEND_AST_PARAM_LIST); }
;