]> granicus.if.org Git - php/commitdiff
Handle const expr __CLASS__ in trait
authorNikita Popov <nikic@php.net>
Mon, 21 Jul 2014 16:21:13 +0000 (18:21 +0200)
committerNikita Popov <nikic@php.net>
Mon, 21 Jul 2014 16:21:13 +0000 (18:21 +0200)
Zend/zend_compile.c

index 5139a11a31987f26fdb7127a5a4aa2b41fa700aa..a1ad07fc008784847043b9843b05de51c1d4c865 100644 (file)
@@ -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;
        }
 }