summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2016-07-14 13:36:43 +0800
committerXinchen Hui <laruence@gmail.com>2016-07-14 13:36:43 +0800
commit8c5b27e0617bf0899d7e830ed3029711125a0ddb (patch)
tree2aa394b891024b750d616b02aad6f468b5558cf3
parent61a2566dc9be62ee8de309496d2a81a12a99947a (diff)
downloadphp-git-8c5b27e0617bf0899d7e830ed3029711125a0ddb.tar.gz
Fixed bug #72594 (Calling an earlier instance of an included anonymous class fatals)
-rw-r--r--NEWS2
-rw-r--r--Zend/tests/bug72594.phpt33
-rw-r--r--Zend/zend_compile.c13
3 files changed, 45 insertions, 3 deletions
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--
+<?php
+if (isset($runtime)) {
+ return new class {
+ public $bar;
+ public function bing($foo = null) {
+ if ($foo) $foo->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);