#26673 [NEW]: Nested object reference count not incremented when object copied?

From: Date: Fri, 19 Dec 2003 23:17:10 +0000
Subject: #26673 [NEW]: Nested object reference count not incremented when object copied?
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-52325@lists.php.net to get a copy of this message
From: samlw at aol dot com Operating system: OS X PHP version: 4.3.4 PHP Bug Type: Scripting Engine problem Bug description: Nested object reference count not incremented when object copied? Description: ------------ In certain cases, the reference counting mechanism seems to become confused when dealing with nested objects. If class 'outer' has a member that is an object of class 'inner', then a copy of an instance of outer sometimes shares the original's reference to inner. As a result, if a change is made to the inner member of the copy, the original's inner is also changed. See the attached code for a working example of this problem. I have reproduced this problem in v 4.3.2 and 4.3.4 running on OS X. Reproduce code: --------------- class inner { var $val1; var $val2; function inner ($val1, $val2) { $this->set($val1, $val2); } function set ($val1, $val2) { $this->val1 = $val1; $this->val2 = $val2; } } class outer { var $val0; var $inner; function outer ($val0, $val1, $val2) { $this->val0 = $val0; $this->inner = new inner($val1, $val2); } function set ($val0, $val1, $val2) { $this->val0 = $val0; $this->inner->set($val1, $val2); } } // construct and dump an object with values [0, 1, 2] $myOuter = new outer(0, 1, 2); var_dump($myOuter); echo '<br />--------<br />'; // change values to [3, 4, 5] $myOuter->set(3, 4, 5); var_dump($myOuter); echo '<br />--------<br />'; // make a COPY and change values to [6, 7, 8] $myOuterCopy = $myOuter; $myOuterCopy->set(6, 7, 8); var_dump($myOuterCopy); echo '<br />--------<br />'; // dump original - should still be [3, 4, 5], but it is [3, 7, 8]!!! // the inner object is not getting copied on modification!!! var_dump($myOuter); echo '<br />--------<br />'; Expected result: ---------------- The final var_dump should produce: object(outer)(2) { ["val0"]=> int(3) ["inner"]=> &object(inner)(2) { ["val1"]=> int(4) ["val2"]=> int(5) } } Actual result: -------------- The final var_dump produces: object(outer)(2) { ["val0"]=> int(3) ["inner"]=> &object(inner)(2) { ["val1"]=> int(7) ["val2"]=> int(8) } } -- Edit bug report at http://bugs.php.net/?id=26673&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=26673&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=26673&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=26673&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=26673&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=26673&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=26673&r=needscript Try newer version: http://bugs.php.net/fix.php?id=26673&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=26673&r=support Expected behavior: http://bugs.php.net/fix.php?id=26673&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=26673&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=26673&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=26673&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=26673&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=26673&r=dst IIS Stability: http://bugs.php.net/fix.php?id=26673&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=26673&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=26673&r=float

« previous php.bugs (#52325) next »