Edit report at https://bugs.php.net/bug.php?id=41132&edit=1
ID: 41132 Comment by: ninzya at inbox dot lv Reported by: wb at pro-net dot co dot uk Summary: No way to get origional object from within __clone() Status: Open Type: Feature/Change Request Package: Feature/Change Request PHP Version: 5.2.1 Block user comment: N Private report: N New Comment: ++ for this. Remark: I think it's still better to pass $originalThis to __clone() as a regular object with no lifted access restrictions to private/protected members (i.e. just pass it as regular fcall argument). Previous Comments: ------------------------------------------------------------------------ [2007-04-18 14:23:15] wb at pro-net dot co dot uk Description: ------------ When you clone an object the __clone method does not have a way to get a reference to the original object. It would be advantageous to have a way to get the original object from within the __clone method. One reason for this is that you can have an object that has child objects that in-turn reference back to the parent object and on clone you want to clone these child objects but would need to remove the original reference and replace it with the new parent reference. This feature could be implemented by simply passing the original object as an argument to the __clone() method. Reproduce code: --------------- class Parent { protected $children = array(); public function __clone($originalThis) { $clonedChildren = array(); foreach($this->children as $child) { $childClone = clone $child; $childClone->attach($this); // we have no way of getting the original // object do we cant do the following... $childClone->detach($originalThis); } $this->children = $clonedChildren; } } Expected result: ---------------- N/A Actual result: -------------- N/A ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=41132&edit=1