From: Nikita Popov Date: Mon, 21 Jul 2014 16:21:13 +0000 (+0200) Subject: Handle const expr __CLASS__ in trait X-Git-Tag: POST_AST_MERGE^2~103 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f8ce5e6efc427fddb7f38a2288667825bb5fe9d2;p=php Handle const expr __CLASS__ in trait --- diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5139a11a31..a1ad07fc00 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -7553,6 +7553,23 @@ void zend_compile_const_expr_resolve_class_name(zend_ast **ast_ptr TSRMLS_DC) { *ast_ptr = zend_ast_create_zval(&result); } +void zend_compile_const_expr_magic_const(zend_ast **ast_ptr TSRMLS_DC) { + zend_ast *ast = *ast_ptr; + zend_class_entry *ce = CG(active_class_entry); + + /* Other cases already resolved by constant folding */ + ZEND_ASSERT(ast->attr == T_CLASS_C && ce && ZEND_CE_IS_TRAIT(ce)); + + { + zval const_zv; + ZVAL_STRING(&const_zv, "__CLASS__"); + Z_TYPE_INFO(const_zv) = IS_CONSTANT_EX; + + zend_ast_destroy(ast); + *ast_ptr = zend_ast_create_zval(&const_zv); + } +} + void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC) { zend_ast *ast = *ast_ptr; if (ast == NULL || ast->kind == ZEND_AST_ZVAL) { @@ -7580,6 +7597,9 @@ void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC) { case ZEND_AST_RESOLVE_CLASS_NAME: zend_compile_const_expr_resolve_class_name(ast_ptr TSRMLS_CC); break; + case ZEND_AST_MAGIC_CONST: + zend_compile_const_expr_magic_const(ast_ptr TSRMLS_CC); + break; } }