#41132 [NEW]: No way to get origional object from within __clone()

From: Date: Wed, 18 Apr 2007 14:23:15 +0000
Subject: #41132 [NEW]: No way to get origional object from within __clone()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-111658@lists.php.net to get a copy of this message
From: wb at pro-net dot co dot uk Operating system: PHP version: 5.2.1 PHP Bug Type: Class/Object related Bug description: No way to get origional object from within __clone() 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 bug report at http://bugs.php.net/?id=41132&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41132&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41132&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41132&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41132&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41132&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41132&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41132&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41132&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41132&r=support Expected behavior: http://bugs.php.net/fix.php?id=41132&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41132&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41132&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41132&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41132&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41132&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41132&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41132&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41132&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41132&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41132&r=mysqlcfg

« previous php.bugs (#111658) next »