]> granicus.if.org Git - php/commitdiff
fixes a syntactical inconsistency with group use and leading `\`
authorMárcio Almada <marcio3w@gmail.com>
Tue, 18 Aug 2015 22:16:06 +0000 (19:16 -0300)
committerMárcio Almada <marcio3w@gmail.com>
Tue, 18 Aug 2015 22:23:58 +0000 (19:23 -0300)
discussion: http://news.php.net/php.internals/87774

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

index 792b2eba1dec9d5fe3bd4da1fe64c80be0965139..ef9ca75bb3f37d4f407eb52935df39b65c109dcd 100644 (file)
@@ -3,7 +3,7 @@ Type group use declarations should not allow override on inner itens
 --FILE--
 <?php
 
-// should not throw syntax errors
+// should throw syntax errors
 
 use const Foo\Bar\{
     A,
diff --git a/Zend/tests/ns_095.phpt b/Zend/tests/ns_095.phpt
new file mode 100644 (file)
index 0000000..9c44964
--- /dev/null
@@ -0,0 +1,51 @@
+--TEST--
+Absolute namespaces should be allowed
+--FILE--
+<?php
+
+namespace Foo\Bar {
+    class ClassA{}
+    class ClassB{}
+    class ClassC{}
+
+    function fn_a(){ return __FUNCTION__; }
+    function fn_b(){ return __FUNCTION__; }
+    function fn_c(){ return __FUNCTION__; }
+
+    const CONST_A = 1;
+    const CONST_B = 2;
+    const CONST_C = 3;
+}
+
+namespace Baz {
+
+    use \Foo\Bar\{ClassA, ClassB, ClassC};
+    use function \Foo\Bar\{fn_a, fn_b, fn_c};
+    use const \Foo\Bar\{CONST_A, CONST_B, CONST_C};
+
+    var_dump(ClassA::class);
+    var_dump(ClassB::class);
+    var_dump(ClassC::class);
+    var_dump(fn_a());
+    var_dump(fn_b());
+    var_dump(fn_c());
+    var_dump(CONST_A);
+    var_dump(CONST_B);
+    var_dump(CONST_C);
+
+    echo "\nDone\n";
+}
+?>
+--EXPECTF--
+
+string(14) "Foo\Bar\ClassA"
+string(14) "Foo\Bar\ClassB"
+string(14) "Foo\Bar\ClassC"
+string(12) "Foo\Bar\fn_a"
+string(12) "Foo\Bar\fn_b"
+string(12) "Foo\Bar\fn_c"
+int(1)
+int(2)
+int(3)
+
+Done
index 39d89775d943db801781ebcee910e4652835595e..8d0965003653bfcfec319963e5b7794e35158831 100644 (file)
@@ -335,13 +335,17 @@ use_type:
 ;
 
 group_use_declaration:
-       namespace_name T_NS_SEPARATOR '{' use_declarations '}'
-               {$$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4); }
+               namespace_name T_NS_SEPARATOR '{' use_declarations '}'
+                       { $$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4); }
+       |       T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' use_declarations '}'
+                       { $$ = zend_ast_create(ZEND_AST_GROUP_USE, $2, $5); }
 ;
 
 mixed_group_use_declaration:
-       namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
-               {$$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4);}
+               namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
+                       { $$ = zend_ast_create(ZEND_AST_GROUP_USE, $1, $4);}
+       |       T_NS_SEPARATOR namespace_name T_NS_SEPARATOR '{' inline_use_declarations '}'
+                       { $$ = zend_ast_create(ZEND_AST_GROUP_USE, $2, $5); }
 ;
 
 inline_use_declarations: