]> granicus.if.org Git - php/commitdiff
Allow optional trailing comma in parameter list
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 26 Mar 2020 15:39:08 +0000 (16:39 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 28 Apr 2020 14:11:08 +0000 (16:11 +0200)
RFC: https://wiki.php.net/rfc/trailing_comma_in_parameter_list

Closes GH-5306.

UPGRADING
Zend/tests/func_sig_trailing_comma.phpt [new file with mode: 0644]
Zend/zend_language_parser.y

index c4eca6daaa0e04663117248c71a6a9dde37a17c4..40a78fcad5868f601f54a53832a5f2aa7c1c6c6d 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -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
diff --git a/Zend/tests/func_sig_trailing_comma.phpt b/Zend/tests/func_sig_trailing_comma.phpt
new file mode 100644 (file)
index 0000000..8153edb
--- /dev/null
@@ -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===
index c75c1e69938656370521570ee6f82175b409a25d..78b6e758ba9dcd7e1a669b5aa2bcee45243598e2 100644 (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); }
 ;