]> granicus.if.org Git - php/commitdiff
Fixed bug #72594 (Calling an earlier instance of an included anonymous class fatals)
authorXinchen Hui <laruence@gmail.com>
Thu, 14 Jul 2016 05:36:43 +0000 (13:36 +0800)
committerXinchen Hui <laruence@gmail.com>
Thu, 14 Jul 2016 05:36:43 +0000 (13:36 +0800)
NEWS
Zend/tests/bug72594.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/NEWS b/NEWS
index 500d2abb7d918b127d9fa1f5bf318d30a0d5a661..f1d56ffc3671cfd3e43e4271644931c16497e522 100644 (file)
--- 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 (file)
index 0000000..3e88b2e
--- /dev/null
@@ -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
+}
index bc4b2fd8f3e0ad7f0bd079c83f997d7b0178bdce..73ccd4a174c12be16e4b4efb3442c7ec27b883f5 100644 (file)
@@ -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);