Skip to content

Commit b248a7a

Browse files
author
Julien Pauli
committed
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: updated NEWS Fix #65419 - Inside trait, self::class != __CLASS__
2 parents 1552d6a + 619adc9 commit b248a7a

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Zend/tests/bug65419.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #65419 (Inside trait, self::class != __CLASS__)
3+
--FILE--
4+
<?php
5+
trait abc
6+
{
7+
static function def()
8+
{
9+
echo self::class, "\n";
10+
echo __CLASS__, "\n";
11+
}
12+
}
13+
14+
class ghi
15+
{
16+
use abc;
17+
}
18+
19+
ghi::def();
20+
?>
21+
--EXPECTF--
22+
ghi
23+
ghi

Zend/zend_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,6 +2214,12 @@ void zend_do_resolve_class_name(znode *result, znode *class_name, int is_static
22142214
if (!CG(active_class_entry)) {
22152215
zend_error_noreturn(E_COMPILE_ERROR, "Cannot access self::class when no class scope is active");
22162216
}
2217+
if (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) {
2218+
constant_name.op_type = IS_CONST;
2219+
ZVAL_STRINGL(&constant_name.u.constant, "class", sizeof("class")-1, 1);
2220+
zend_do_fetch_constant(result, class_name, &constant_name, ZEND_RT, 1 TSRMLS_CC);
2221+
break;
2222+
}
22172223
zval_dtor(&class_name->u.constant);
22182224
class_name->op_type = IS_CONST;
22192225
ZVAL_STRINGL(&class_name->u.constant, CG(active_class_entry)->name, CG(active_class_entry)->name_length, 1);

0 commit comments

Comments
 (0)