]> granicus.if.org Git - php/commitdiff
- Fixed bug #55086 (Namespace alias does not work inside trait's use block)
authorFelipe Pena <felipe@php.net>
Sat, 2 Jul 2011 17:12:20 +0000 (17:12 +0000)
committerFelipe Pena <felipe@php.net>
Sat, 2 Jul 2011 17:12:20 +0000 (17:12 +0000)
  patch by: Pierrick

Zend/tests/bug55086.phpt [new file with mode: 0644]
Zend/zend_compile.c
Zend/zend_language_parser.y

diff --git a/Zend/tests/bug55086.phpt b/Zend/tests/bug55086.phpt
new file mode 100644 (file)
index 0000000..9a5c747
--- /dev/null
@@ -0,0 +1,36 @@
+--TEST--
+Bug #55086 (Namespace alias does not work inside trait's use block)
+--FILE--
+<?php
+namespace N1 {
+
+    trait T1 {
+        public function hello() { return 'hello from t1'; }
+    }
+
+    trait T2 {
+        public function hello() { return 'hello from t2'; }
+    }
+
+}
+namespace N2 {
+    use N1\T1;
+    use N1\T2;
+    class A {
+        use T1, T2 {
+            T1::hello insteadof T2;
+            T1::hello as foo;
+        }
+    }
+    $a = new A;
+    echo $a->hello(), PHP_EOL;
+    echo $a->foo(), PHP_EOL;
+    try {
+    } catch(namespace \Foo $e)
+    {
+    }
+}
+?>
+--EXPECT--
+hello from t1
+hello from t1
index 7842ec8f2ef0033fbd419dd815d77a8f1a76806c..5f9cef311bf72b7976d2115e93043866b3523239 100644 (file)
@@ -4052,6 +4052,8 @@ void zend_prepare_reference(znode *result, znode *class_name, znode *method_name
        /* REM: There should not be a need for copying, 
           zend_do_begin_class_declaration is also just using that string */
        if (class_name) {
+               ulong fetch_type = ZEND_FETCH_CLASS_GLOBAL;
+               zend_resolve_class_name(class_name, &fetch_type, 1 TSRMLS_CC);
                method_ref->class_name = Z_STRVAL(class_name->u.constant);
                method_ref->cname_len  = Z_STRLEN(class_name->u.constant);
        } else {
index 3d774bff250081fb219371bc44b46e19957b0bd2..4dd5bdb977ea59b65d1a42cc3281c93c82219b2d 100644 (file)
@@ -612,8 +612,8 @@ trait_precedence:
 ;
 
 trait_reference_list:
-               fully_qualified_class_name                                                                      { zend_init_list(&$$.u.op.ptr, Z_STRVAL($1.u.constant) TSRMLS_CC); }
-       |       trait_reference_list ',' fully_qualified_class_name                     { zend_add_to_list(&$1.u.op.ptr, Z_STRVAL($3.u.constant) TSRMLS_CC); $$ = $1; }
+               fully_qualified_class_name                                                                      { ulong fetch_type = ZEND_FETCH_CLASS_GLOBAL; zend_resolve_class_name(&$1, &fetch_type, 1 TSRMLS_CC); zend_init_list(&$$.u.op.ptr, Z_STRVAL($1.u.constant) TSRMLS_CC); }
+       |       trait_reference_list ',' fully_qualified_class_name                     { ulong fetch_type = ZEND_FETCH_CLASS_GLOBAL; zend_resolve_class_name(&$3, &fetch_type, 1 TSRMLS_CC); zend_add_to_list(&$1.u.op.ptr, Z_STRVAL($3.u.constant) TSRMLS_CC); $$ = $1; }
 ;
 
 trait_method_reference: