#33128 [NEW]: Cloning of objects containing other objects leads to referencing
| From: | p dot seizov at decart dot bg | Date: | Tue, 24 May 2005 15:11:57 +0000 |
| Subject: | #33128 [NEW]: Cloning of objects containing other objects leads to referencing | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-79446@lists.php.net to get a copy of this message | ||
From: p dot seizov at decart dot bg
Operating system: Windows, Linux
PHP version: 5.0.4
PHP Bug Type: Class/Object related
Bug description: Cloning of objects containing other objects leads to referencing
Description:
------------
If you clone an object containing another object, the second object is
actually referenced to the original. So if you change the cloned
subobject, it will change the original.
Reproduce code:
---------------
class ParentObject
{
public $value;
public $subObject;
}
class SubObject
{
public $value;
}
$subObject = new SubObject();
$subObject->value = 1;
$parentObject = new ParentObject();
$parentObject->value = 1;
$parentObject->subObject = clone $subObject;
$clonedObject = clone $parentObject;
$clonedObject->value = 2;
$clonedObject->subObject->value = 2;
echo $parentObject->value."\r\n";
echo $parentObject->subObject->value."\r\n";
Expected result:
----------------
1
1
Actual result:
--------------
1
2
--
Edit bug report at http://bugs.php.net/?id=33128&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33128&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33128&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33128&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33128&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33128&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33128&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33128&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33128&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33128&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33128&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=33128&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=33128&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33128&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33128&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33128&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33128&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33128&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33128&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33128&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33128&r=mysqlcfg