diff --git a/Zend/tests/bug72594.phpt b/Zend/tests/bug72594.phpt new file mode 100644 index 00000000000..3e88b2e6d67 --- /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 c6eb087eddc..9a4ff33950b 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5931,7 +5931,15 @@ void zend_compile_class_decl(zend_ast *ast) /* {{{ */ opline->opcode = ZEND_DECLARE_ANON_CLASS; } - 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; @@ -6218,7 +6226,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);