]> granicus.if.org Git - php/commitdiff
Support optional comma in closure use list
authorTyson Andre <tysonandre775@hotmail.com>
Wed, 1 Jul 2020 17:28:39 +0000 (13:28 -0400)
committerTyson Andre <tysonandre775@hotmail.com>
Tue, 21 Jul 2020 17:01:27 +0000 (13:01 -0400)
RFC: https://wiki.php.net/rfc/trailing_comma_in_closure_use_list
Discussion: https://externals.io/message/110715

The release manager has agreed to allow merging of RFCs that have near-unanimous
votes. If an RFC ends up not achieving the required 2/3 majority at the time the
announced voting period closes, this implementation commit will be reverted
in time for the feature freeze.

Closes GH-5793

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

diff --git a/Zend/tests/closure_use_trailing_comma.phpt b/Zend/tests/closure_use_trailing_comma.phpt
new file mode 100644 (file)
index 0000000..7bf6e5c
--- /dev/null
@@ -0,0 +1,17 @@
+--TEST--
+Closure use list can have trailing commas
+--FILE--
+<?php
+
+$b = 'test';
+$fn = function () use (
+    $b,
+    &$a,
+) {
+    $a = $b;
+};
+$fn();
+echo "$a\n";
+?>
+--EXPECT--
+test
index 40938256f2a5ef7b457a75e2e0578d4d7504d1dc..891624c461f67daf809d3bd330a37c479afa5c03 100644 (file)
@@ -1155,7 +1155,7 @@ returns_ref:
 
 lexical_vars:
                %empty { $$ = NULL; }
-       |       T_USE '(' lexical_var_list ')' { $$ = $3; }
+       |       T_USE '(' lexical_var_list possible_comma ')' { $$ = $3; }
 ;
 
 lexical_var_list: