note 69832 added to language.oop5.cloning
| From: | felixgilcher at osu1 dot php dot net | Date: | Fri, 22 Sep 2006 14:20:03 +0000 |
| Subject: | note 69832 added to language.oop5.cloning | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117426@lists.php.net to get a copy of this message | ||
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
----
Server IP: 212.124.37.9
Probable Submitter: 217.27.204.139
----
Manual Page -- http://www.php.net/manual/en/language.oop5.cloning.php
Edit -- https://master.php.net/note/edit/69832
Del: integrated -- https://master.php.net/note/delete/69832/integrated
Del: useless -- https://master.php.net/note/delete/69832/useless
Del: bad code -- https://master.php.net/note/delete/69832/bad+code
Del: spam -- https://master.php.net/note/delete/69832/spam
Del: non-english -- https://master.php.net/note/delete/69832/non-english
Del: in docs -- https://master.php.net/note/delete/69832/in+docs
Del: other reasons-- https://master.php.net/note/delete/69832
Reject -- https://master.php.net/note/reject/69832
Search -- https://master.php.net/manage/user-notes.php