note 94571 deleted from language.oop5.cloning by danbrown

From: Date: Thu, 12 Nov 2009 16:28:10 +0000
Subject: note 94571 deleted from language.oop5.cloning by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-162810@lists.php.net to get a copy of this message
Note Submitter: rarioj at gmail dot com ---- The method __clone() described by "cheetah at tanabi dot org" works flawlessly. But one thing to note that sometimes an object implements its own cloning logic. By unserialize-serialize-ing this object will not invoke the internal __clone() method. This is the revised version: <?php function __clone() { foreach ($this as $key => $val) { if (is_object($val)) { if (method_exists($val, '__clone')) { $this->{$key} = clone $val; } else { $this->{$key} = unserialize(serialize($val)); } } else if (is_array($val)) { $this->{$key} = unserialize(serialize($val)); } } } ?>

« previous php.notes (#162810) next »