diff options
author | Julien Pauli <jpauli@php.net> | 2014-10-29 14:35:51 +0100 |
---|---|---|
committer | Julien Pauli <jpauli@php.net> | 2014-11-28 13:24:25 +0100 |
commit | 7c77ca38b1e3ea7a707380c731b237c2c480e093 (patch) | |
tree | 3f53960d16eea3aacd25f5d0d41a74f446ddc15f | |
parent | 42af41162026f3d8dfc86e7afbf860d3605e427a (diff) | |
download | php-git-7c77ca38b1e3ea7a707380c731b237c2c480e093.tar.gz |
Fix #65419 - Inside trait, self::class != __CLASS__
-rw-r--r-- | Zend/tests/bug65419.phpt | 23 | ||||
-rw-r--r-- | Zend/zend_compile.c | 6 |
2 files changed, 29 insertions, 0 deletions
diff --git a/Zend/tests/bug65419.phpt b/Zend/tests/bug65419.phpt new file mode 100644 index 0000000000..677b2750f2 --- /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 6e1912803e..ae9409e715 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); |