Skip to content
Browse files

Allowed import of global classes "use ::GlobalClassName;"

  • Loading branch information...
1 parent 80e77c1 commit 64e8f223556d905ff23df31ec40335528113e40c Dmitry Stogov committed Dec 13, 2007
Showing with 28 additions and 5 deletions.
  1. +9 −0 Zend/tests/ns_061.phpt
  2. +12 −0 Zend/tests/ns_062.phpt
  3. +2 −2 Zend/zend_compile.c
  4. +1 −1 Zend/zend_compile.h
  5. +4 −2 Zend/zend_language_parser.y
View
9 Zend/tests/ns_061.phpt
@@ -0,0 +1,9 @@
+--TEST--
+061: use in global scope
+--FILE--
+<?php
+class A {}
+use ::A as B;
+echo get_class(new B)."\n";
+--EXPECT--
+A
View
12 Zend/tests/ns_062.phpt
@@ -0,0 +1,12 @@
+--TEST--
+062: use ::global class
+--FILE--
+<?php
+namespace Foo;
+use ::stdClass;
+use ::stdClass as A;
+echo get_class(new stdClass)."\n";
+echo get_class(new A)."\n";
+--EXPECT--
+stdClass
+stdClass
View
4 Zend/zend_compile.c
@@ -4777,7 +4777,7 @@ void zend_do_namespace(znode *name TSRMLS_DC) /* {{{ */
}
/* }}} */
-void zend_do_use(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
+void zend_do_use(znode *ns_name, znode *new_name, int is_global TSRMLS_DC) /* {{{ */
{
char *lcname;
zval *name, *ns, tmp;
@@ -4804,7 +4804,7 @@ void zend_do_use(znode *ns_name, znode *new_name TSRMLS_DC) /* {{{ */
} else {
*name = *ns;
zval_copy_ctor(name);
- warn = 1;
+ warn = !is_global;
}
}
View
2 Zend/zend_compile.h
@@ -510,7 +510,7 @@ void zend_do_abstract_method(znode *function_name, znode *modifiers, znode *body
void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC);
void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC);
void zend_do_namespace(znode *name TSRMLS_DC);
-void zend_do_use(znode *name, znode *new_name TSRMLS_DC);
+void zend_do_use(znode *name, znode *new_name, int is_global TSRMLS_DC);
void zend_do_end_compilation(TSRMLS_D);
ZEND_API void function_add_ref(zend_function *function);
View
6 Zend/zend_language_parser.y
@@ -168,8 +168,10 @@ top_statement:
| class_declaration_statement { zend_do_early_binding(TSRMLS_C); }
| T_HALT_COMPILER '(' ')' ';' { zend_do_halt_compiler_register(TSRMLS_C); YYACCEPT; }
| T_NAMESPACE namespace_name ';' { zend_do_namespace(&$2 TSRMLS_CC); }
- | T_USE namespace_name ';' { zend_do_use(&$2, NULL TSRMLS_CC); }
- | T_USE namespace_name T_AS T_STRING ';' { zend_do_use(&$2, &$4 TSRMLS_CC); }
+ | T_USE namespace_name ';' { zend_do_use(&$2, NULL, 0 TSRMLS_CC); }
+ | T_USE namespace_name T_AS T_STRING ';' { zend_do_use(&$2, &$4, 0 TSRMLS_CC); }
+ | T_USE T_PAAMAYIM_NEKUDOTAYIM T_STRING ';' { zend_do_use(&$3, NULL, 1 TSRMLS_CC); }
+ | T_USE T_PAAMAYIM_NEKUDOTAYIM T_STRING T_AS T_STRING ';' { zend_do_use(&$3, &$5, 1 TSRMLS_CC); }
| constant_declaration ';'
;

0 comments on commit 64e8f22

Please sign in to comment.
Something went wrong with that request. Please try again.