From 8c5b27e0617bf0899d7e830ed3029711125a0ddb Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Thu, 14 Jul 2016 13:36:43 +0800 Subject: [PATCH] Fixed bug #72594 (Calling an earlier instance of an included anonymous class fatals) --- NEWS | 2 ++ Zend/tests/bug72594.phpt | 33 +++++++++++++++++++++++++++++++++ Zend/zend_compile.c | 13 ++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 Zend/tests/bug72594.phpt diff --git a/NEWS b/NEWS index 500d2abb7d..f1d56ffc36 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,8 @@ PHP NEWS ?? ??? 2016 PHP 7.0.10 - Core: + . Fixed bug #72594 (Calling an earlier instance of an included anonymous + class fatals). (Laruence) . Fixed bug #72581 (previous property undefined in Exception after deserialization). (Laruence) . Fixed bug #72496 (Cannot declare public method with signature incompatible diff --git a/Zend/tests/bug72594.phpt b/Zend/tests/bug72594.phpt new file mode 100644 index 0000000000..3e88b2e6d6 --- /dev/null +++ b/Zend/tests/bug72594.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #72594 (Calling an earlier instance of an included anonymous class fatals) +--INI-- +opcache.enable=0 +--FILE-- +bing(); + } + }; +} + +$runtime = 1; +$oldFoo = require(__FILE__); +$newFoo = require(__FILE__); + +var_dump(get_class_methods($oldFoo)); +var_dump(get_object_vars($oldFoo)); + +$newFoo->bing($oldFoo); +?> +--EXPECTF-- +array(1) { + [0]=> + string(4) "bing" +} +array(1) { + ["bar"]=> + NULL +} diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index bc4b2fd8f3..73ccd4a174 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5283,7 +5283,7 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ opline = get_next_op(CG(active_op_array)); zend_make_var_result(&declare_node, opline); - // TODO.AST drop this + /* TODO.AST drop this */ GET_NODE(&FC(implementing_class), opline->result); opline->op2_type = IS_CONST; @@ -5299,7 +5299,15 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ opline->op1_type = IS_UNUSED; - zend_hash_update_ptr(CG(class_table), lcname, ce); + if (!zend_hash_exists(CG(class_table), lcname)) { + zend_hash_add_ptr(CG(class_table), lcname, ce); + } else { + /* this anonymous class has been included */ + zval zv; + ZVAL_PTR(&zv, ce); + destroy_zend_class(&zv); + return; + } } else { zend_string *key; @@ -5586,7 +5594,6 @@ void zend_compile_group_use(zend_ast *ast) /* {{{ */ } /* }}} */ - void zend_compile_const_decl(zend_ast *ast) /* {{{ */ { zend_ast_list *list = zend_ast_get_list(ast); -- 2.40.0