Fix #65419 - Inside trait, self::class != __CLASS__
authorJulien Pauli <jpauli@php.net>
Wed, 29 Oct 2014 13:35:51 +0000 (14:35 +0100)
committerJulien Pauli <jpauli@php.net>
Fri, 28 Nov 2014 12:24:25 +0000 (13:24 +0100)
Zend/tests/bug65419.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/bug65419.phpt b/Zend/tests/bug65419.phpt
new file mode 100644 (file)
index 0000000..677b275
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #65419 (Inside trait, self::class != __CLASS__)
+--FILE--
+<?php
+trait abc
+{
+  static function def()
+  {
+    echo self::class, "\n";
+    echo __CLASS__, "\n";
+  }
+}
+
+class ghi
+{
+  use abc;
+}
+
+ghi::def();
+?>
+--EXPECTF--
+ghi
+ghi
\ No newline at end of file
index 6e1912803e6a53ad052a70c61d710b65f1b37f9f..ae9409e715ac2e67d133ec46a6cea026a68b118a 100644 (file)
@@ -2140,6 +2140,12 @@ void zend_do_resolve_class_name(znode *result, znode *class_name, int is_static
                        if (!CG(active_class_entry)) {
                                zend_error(E_COMPILE_ERROR, "Cannot access self::class when no class scope is active");
                        }
+                       if (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) {
+                               constant_name.op_type = IS_CONST;
+                               ZVAL_STRINGL(&constant_name.u.constant, "class", sizeof("class")-1, 1);
+                               zend_do_fetch_constant(result, class_name, &constant_name, ZEND_RT, 1 TSRMLS_CC);
+                               break;
+                       }
                        zval_dtor(&class_name->u.constant);
                        class_name->op_type = IS_CONST;
                        ZVAL_STRINGL(&class_name->u.constant, CG(active_class_entry)->name, CG(active_class_entry)->name_length, 1);