note 69832 deleted from language.oop5.cloning by danielc

From: Date: Sun, 27 Jul 2008 05:31:52 +0000
Subject: note 69832 deleted from language.oop5.cloning by danielc
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142803@lists.php.net to get a copy of this message
Note Submitter: felix gilcher Reason: 0 ---- Copying objects with <?php public function copy() { $serialized_contents = serialize($this); return unserialize($serialized_contents); } ?> is a pretty dangerous thing. What if your objects hold references to very large shared objects? They all get copied as well. Serializing objects may break database connections and references. What you probably want to do is implement a proper __clone() method for each of your classes so that each object in your tree gets to decide what subobjects need to be copied and which ones should better remain untouched. regards felix

« previous php.notes (#142803) next »