summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
Diffstat (limited to 'Zend')
-rw-r--r--Zend/tests/ns_088.phpt2
-rw-r--r--Zend/tests/ns_094.phpt2
-rw-r--r--Zend/tests/ns_trailing_comma_01.phpt30
-rw-r--r--Zend/tests/ns_trailing_comma_02.phpt52
-rw-r--r--Zend/tests/ns_trailing_comma_error_01.phpt8
-rw-r--r--Zend/tests/ns_trailing_comma_error_02.phpt8
-rw-r--r--Zend/tests/ns_trailing_comma_error_03.phpt8
-rw-r--r--Zend/tests/ns_trailing_comma_error_04.phpt8
-rw-r--r--Zend/tests/ns_trailing_comma_error_05.phpt8
-rw-r--r--Zend/tests/ns_trailing_comma_error_06.phpt8
-rw-r--r--Zend/tests/ns_trailing_comma_error_07.phpt8
-rw-r--r--Zend/tests/ns_trailing_comma_error_08.phpt8
-rw-r--r--Zend/zend_language_parser.y13
13 files changed, 157 insertions, 6 deletions
diff --git a/Zend/tests/ns_088.phpt b/Zend/tests/ns_088.phpt
index 7af8dcc8d3..18210da6df 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 16001da67e..f33bf560a9 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 0000000000..cbd443f0f7
--- /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 0000000000..658a1734af
--- /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 0000000000..6ada1f7bf2
--- /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 0000000000..c9d0d92dee
--- /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 0000000000..9d10c47dcc
--- /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 0000000000..d04b1af272
--- /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 0000000000..1d43e8fe32
--- /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 0000000000..2f2738e204
--- /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 0000000000..c60dd6a4b0
--- /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 0000000000..b23446301d
--- /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 9970ce3a07..f1a7e38893 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); }