|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-05-24 18:31 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 06:00:01 2025 UTC |
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