com php-src: Fixed Bug #69996 (Changing the property of a cloned object affects the original): NEWS Zend/tests/bug69996.phpt Zend/zend_execute.c
| From: | Xinchen Hui | Date: | Fri, 10 Jul 2015 08:33:13 +0000 |
| Subject: | com php-src: Fixed Bug #69996 (Changing the property of a cloned object affects the original): NEWS Zend/tests/bug69996.phpt Zend/zend_execute.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-87900@lists.php.net to get a copy of this message | ||
Commit: f930d6ea0e8ca8723212ab234973d74dbccfc226
Author: Xinchen Hui <laruence@php.net> Fri, 10 Jul 2015 16:33:13 +0800
Parents: 54305c89522b7938a2e47080e189dac1ad665cd7
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f930d6ea0e8ca8723212ab234973d74dbccfc226
Log:
Fixed Bug #69996 (Changing the property of a cloned object affects the original)
Bugs:
https://bugs.php.net/69996
Changed paths:
M NEWS
A Zend/tests/bug69996.phpt
M Zend/zend_execute.c
Diff:
diff --git a/NEWS b/NEWS
index 547ed46..989c1cc 100644
--- 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
index 0000000..178e368
--- /dev/null
+++ b/Zend/tests/bug69996.phpt
@@ -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"
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c
index 257f627..98a7f27 100644
--- a/Zend/zend_execute.c
+++ b/Zend/zend_execute.c
@@ -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;