com php-src: Fix #65419 - Inside trait, self::class != __CLASS__: Zend/tests/bug65419.p hpt Zend/zend_compile.c
| From: | JulienPauli | Date: | Fri, 28 Nov 2014 12:24:25 +0000 |
| Subject: | com php-src: Fix #65419 - Inside trait, self::class != __CLASS__: Zend/tests/bug65419.p hpt Zend/zend_compile.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-83369@lists.php.net to get a copy of this message | ||
Commit: 7c77ca38b1e3ea7a707380c731b237c2c480e093
Author: Julien Pauli <jpauli@php.net> Wed, 29 Oct 2014 14:35:51 +0100
Parents: 42af41162026f3d8dfc86e7afbf860d3605e427a
Branches: PHP-5.5
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7c77ca38b1e3ea7a707380c731b237c2c480e093
Log:
Fix #65419 - Inside trait, self::class != __CLASS__
Bugs:
https://bugs.php.net/65419
Changed paths:
A Zend/tests/bug65419.phpt
M Zend/zend_compile.c
Diff:
diff --git a/Zend/tests/bug65419.phpt b/Zend/tests/bug65419.phpt
new file mode 100644
index 0000000..677b275
--- /dev/null
+++ b/Zend/tests/bug65419.phpt
@@ -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
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 6e19128..ae9409e 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -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);