]> granicus.if.org Git - php/commitdiff
Fixed Bug #69996 (Changing the property of a cloned object affects the original)
authorXinchen Hui <laruence@php.net>
Fri, 10 Jul 2015 08:33:13 +0000 (16:33 +0800)
committerXinchen Hui <laruence@php.net>
Fri, 10 Jul 2015 08:33:13 +0000 (16:33 +0800)
NEWS
Zend/tests/bug69996.phpt [new file with mode: 0644]
Zend/zend_execute.c

diff --git a/NEWS b/NEWS
index 547ed4667ef4952431534f81ef5c76490a2ada36..989c1cc2711cbc3eb25846287d3649a397818ab5 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@
 
 - Core:
   . Fixed bug #70012 (Exception lost with nested finally block). (Laruence)
+  . Fixed bug #69996 (Changing the property of a cloned object affects the
+    original). (Dmitry, Laruence)
 
 - Soap:
   . Fixed bug #70032 (make_http_soap_request calls
diff --git a/Zend/tests/bug69996.phpt b/Zend/tests/bug69996.phpt
new file mode 100644 (file)
index 0000000..178e368
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #69996 (Changing the property of a cloned object affects the original)
+--FILE--
+<?php
+
+function method($cache) {
+         $prepared = clone $cache;
+         var_dump($prepared->data);
+         $prepared->data = "bad";
+         return $prepared;
+}
+
+$cache = new stdClass();
+$cache->data = "good";
+
+for ($i = 0; $i < 5; ++$i) {
+          method($cache);
+}
+?>
+--EXPECT--
+string(4) "good"
+string(4) "good"
+string(4) "good"
+string(4) "good"
+string(4) "good"
index 257f627d22578d068a1205150f60220798968af9..98a7f2785bfff7a52980b3065f21a0b68fcae536 100644 (file)
@@ -1110,6 +1110,12 @@ fast_assign:
                        }
                } else {
                        if (EXPECTED(zobj->properties != NULL)) {
+                               if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) {
+                                       if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) {
+                                               GC_REFCOUNT(zobj->properties)--;
+                                       }
+                                       zobj->properties = zend_array_dup(zobj->properties);
+                               }
                                property = zend_hash_find(zobj->properties, Z_STR_P(property_name));
                                if (property) {
                                        goto fast_assign;