com php-src: Add trailing comma syntax support for mixed and unmixed group use lists: NEWS UPGRADING Zend/tests/ns_088.phpt Ze nd/tests/ns_094.phpt Zend/tests/ns_trailing_com ma_01.phpt Zend/tests/ns_trailing_comma_02 .phpt Zend/tests/ns_trailing_comma_error_01.p hpt Zend/tests/ns_trailing_comma_error_02.phpt Zend/tests/ns_trailing_comma_error_03.phpt Z end/tests/ns_trailing_comma_error_04.phpt Zend/ tests/ns_trailing_comma_error_05.phpt Zend/test s/ns_

[email protected] (Nikita Popov)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    12300f465e5bed1fa7d0bc445aef68b6a2753c3b
Author:    Sammy Kaye Powers <[email protected]>         Thu, 20 Apr 2017 13:08:11 -0500
Committer: Nikita Popov <[email protected]>      Mon, 1 May 2017 12:19:47 +0200
Parents:   1f42a50840e7462a4c1ad94a32730baee9ecf707
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=12300f465e5bed1fa7d0bc445aef68b6a2753c3b

Log:
Add trailing comma syntax support for mixed and unmixed group use lists

RFC: https://wiki.php.net/rfc/list-syntax-trailing-commas

Changed paths:
  M  NEWS
  M  UPGRADING
  M  Zend/tests/ns_088.phpt
  M  Zend/tests/ns_094.phpt
  A  Zend/tests/ns_trailing_comma_01.phpt
  A  Zend/tests/ns_trailing_comma_02.phpt
  A  Zend/tests/ns_trailing_comma_error_01.phpt
  A  Zend/tests/ns_trailing_comma_error_02.phpt
  A  Zend/tests/ns_trailing_comma_error_03.phpt
  A  Zend/tests/ns_trailing_comma_error_04.phpt
  A  Zend/tests/ns_trailing_comma_error_05.phpt
  A  Zend/tests/ns_trailing_comma_error_06.phpt
  A  Zend/tests/ns_trailing_comma_error_07.phpt
  A  Zend/tests/ns_trailing_comma_error_08.phpt
  M  Zend/zend_language_parser.y
diff_12300f465e5bed1fa7d0bc445aef68b6a2753c3b.txt (text/plain, 8.6 KB)
diff --git a/NEWS b/NEWS
index 963fff2..a699815 100644
--- a/NEWS
+++ b/NEWS
@@ -39,6 +39,8 @@ PHP                                                                        NEWS
   . Fixed bug #74149 (static embed SAPI linkage error). (krakjoe)
   . Fixed bug #72359, bug #72451, bug #73706, bug #71115 and others related
     to interned strings handling in TS builds. (Anatol, Dmitry)
+  . Implemented "Trailing Commas In List Syntax" RFC for group use lists only.
+    (Sammy Kaye Powers)
 
 - BCMath:
   . Fixed bug #46564 (bcmod truncates fractionals). (liborm85)
diff --git a/UPGRADING b/UPGRADING
index baead9d..e187766 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -99,6 +99,8 @@ PHP 7.2 UPGRADE NOTES
     inherited method. This complies with contravariance of method argument types
     under the Liskov Substitution Principle.
     (https://wiki.php.net/rfc/parameter-no-type-variance)
+  . A trailing comma in group use statements is now allowed.
+    (https://wiki.php.net/rfc/list-syntax-trailing-commas)
 
 - PCRE:
   . Added `J` modifier for setting PCRE_DUPNAMES.
diff --git a/Zend/tests/ns_088.phpt b/Zend/tests/ns_088.phpt
index 7af8dcc..18210da 100644
--- a/Zend/tests/ns_088.phpt
+++ b/Zend/tests/ns_088.phpt
@@ -14,4 +14,4 @@ namespace Fiz\Biz\Buz {
 }
 ?>
 --EXPECTF--
-Parse error: syntax error, unexpected '{', expecting ',' or '}' in %sns_088.php on line 5
+Parse error: syntax error, unexpected '{', expecting '}' in %sns_088.php on line 5
diff --git a/Zend/tests/ns_094.phpt b/Zend/tests/ns_094.phpt
index 16001da..f33bf56 100644
--- a/Zend/tests/ns_094.phpt
+++ b/Zend/tests/ns_094.phpt
@@ -12,4 +12,4 @@ use const Foo\Bar\{
 };
 
 --EXPECTF--
-Parse error: syntax error, unexpected 'const' (T_CONST), expecting identifier (T_STRING) in %s on line 7
+Parse error: syntax error, unexpected 'const' (T_CONST), expecting '}' in %s on line 7
diff --git a/Zend/tests/ns_trailing_comma_01.phpt b/Zend/tests/ns_trailing_comma_01.phpt
new file mode 100644
index 0000000..cbd443f
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_01.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Mixed group use declaration can contain trailing comma
+--FILE--
+<?php
+namespace Foo {
+  const FOO_CONST = "Foo const\n";
+  function foo_func() {
+    echo "Foo func\n";
+  }
+  class FooClass {
+    function __construct() {
+      echo "Foo class\n";
+    }
+  }
+}
+namespace {
+  use Foo\{
+    const FOO_CONST,
+    function foo_func,
+    FooClass as BarClass,
+  };
+  echo FOO_CONST;
+  foo_func();
+  new BarClass;
+}
+?>
+--EXPECT--
+Foo const
+Foo func
+Foo class
diff --git a/Zend/tests/ns_trailing_comma_02.phpt b/Zend/tests/ns_trailing_comma_02.phpt
new file mode 100644
index 0000000..658a173
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_02.phpt
@@ -0,0 +1,52 @@
+--TEST--
+Unmixed group use declaration can contain trailing comma
+--FILE--
+<?php
+namespace Foo {
+  const FOO_CONST_1 = "Foo const 1\n";
+  const FOO_CONST_2 = "Foo const 2\n";
+}
+namespace Bar {
+  function foo_func_1() {
+    echo "Bar func 1\n";
+  }
+  function foo_func_2() {
+    echo "Bar func 2\n";
+  }
+}
+namespace Baz {
+  class BazFooClass {
+    function __construct() { echo "BazFoo class\n"; }
+  }
+  class BazBarClass {
+    function __construct() { echo "BazBar class\n"; }
+  }
+}
+namespace {
+  use const Foo\{
+    FOO_CONST_1,
+    FOO_CONST_2,
+  };
+  use function Bar\{
+    foo_func_1,
+    foo_func_2,
+  };
+  use Baz\{
+    BazFooClass,
+    BazBarClass,
+  };
+  echo FOO_CONST_1;
+  echo FOO_CONST_2;
+  foo_func_1();
+  foo_func_2();
+  new BazFooClass;
+  new BazBarClass;
+}
+?>
+--EXPECT--
+Foo const 1
+Foo const 2
+Bar func 1
+Bar func 2
+BazFoo class
+BazBar class
diff --git a/Zend/tests/ns_trailing_comma_error_01.phpt b/Zend/tests/ns_trailing_comma_error_01.phpt
new file mode 100644
index 0000000..6ada1f7
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_01.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Group use declarations mustn't be empty
+--FILE--
+<?php
+use Baz\{};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected '}', expecting identifier (T_STRING) or function (T_FUNCTION) or const (T_CONST) in %s on line %d
\ No newline at end of file
diff --git a/Zend/tests/ns_trailing_comma_error_02.phpt b/Zend/tests/ns_trailing_comma_error_02.phpt
new file mode 100644
index 0000000..c9d0d92
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_02.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Group use declarations mustn't contain just a comma
+--FILE--
+<?php
+use Baz\{,};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected ',', expecting identifier (T_STRING) or function (T_FUNCTION) or const (T_CONST) in %s on line %d
\ No newline at end of file
diff --git a/Zend/tests/ns_trailing_comma_error_03.phpt b/Zend/tests/ns_trailing_comma_error_03.phpt
new file mode 100644
index 0000000..9d10c47
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_03.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Group use declarations mustn't allow more than one comma
+--FILE--
+<?php
+use Baz\{Foo,,};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
\ No newline at end of file
diff --git a/Zend/tests/ns_trailing_comma_error_04.phpt b/Zend/tests/ns_trailing_comma_error_04.phpt
new file mode 100644
index 0000000..d04b1af
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_04.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Group use declarations mustn't begin with a comma
+--FILE--
+<?php
+use Baz\{,Foo};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected ',', expecting identifier (T_STRING) or function (T_FUNCTION) or const (T_CONST) in %s on line %d
\ No newline at end of file
diff --git a/Zend/tests/ns_trailing_comma_error_05.phpt b/Zend/tests/ns_trailing_comma_error_05.phpt
new file mode 100644
index 0000000..1d43e8f
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_05.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Group use declarations mustn't contain two commas mid-list
+--FILE--
+<?php
+use Baz\{Foo,,Bar};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
\ No newline at end of file
diff --git a/Zend/tests/ns_trailing_comma_error_06.phpt b/Zend/tests/ns_trailing_comma_error_06.phpt
new file mode 100644
index 0000000..2f2738e
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_06.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Unmixed group use declarations mustn't allow more than one comma
+--FILE--
+<?php
+use const Baz\{Foo,,};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
\ No newline at end of file
diff --git a/Zend/tests/ns_trailing_comma_error_07.phpt b/Zend/tests/ns_trailing_comma_error_07.phpt
new file mode 100644
index 0000000..c60dd6a
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_07.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Unmixed group use declarations mustn't begin with a comma
+--FILE--
+<?php
+use function Baz\{,Foo};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected ',', expecting identifier (T_STRING) in %s on line %d
\ No newline at end of file
diff --git a/Zend/tests/ns_trailing_comma_error_08.phpt b/Zend/tests/ns_trailing_comma_error_08.phpt
new file mode 100644
index 0000000..b234463
--- /dev/null
+++ b/Zend/tests/ns_trailing_comma_error_08.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Unmixed group use declarations mustn't contain two commas mid-list
+--FILE--
+<?php
+use const Baz\{Foo,,Bar};
+?>
+--EXPECTF--
+Parse error: syntax error, unexpected ',', expecting '}' in %s on line %d
\ No newline at end of file
diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y
index 9970ce3..f1a7e38 100644
--- a/Zend/zend_language_parser.y
+++ b/Zend/zend_language_parser.y
@@ -338,19 +338,24 @@ use_type:
 ;
 
 group_use_declaration:
-		namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
+		namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4); }
-	|	T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations '}'
+	|	T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' unprefixed_use_declarations possible_comma '}'
 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $2, $5); }
 ;
 
 mixed_group_use_declaration:
-		namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
+		namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4);}
-	|	T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
+	|	T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations possible_comma '}'
 			{ $$ = zend_ast_create(ZEND_AST_GROUP_USE, $2, $5); }
 ;
 
+possible_comma:
+		/* empty */
+	|	','
+;
+
 inline_use_declarations:
 		inline_use_declarations ',' inline_use_declaration
 			{ $$ = zend_ast_list_add($1, $3); }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.