note 87066 modified in language.oop5.cloning by thiago
| From: | thiago@php.net | Date: | Tue, 18 Nov 2008 14:55:33 +0000 |
| Subject: | note 87066 modified in language.oop5.cloning by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-146644@lists.php.net to get a copy of this message | ||
Want deep cloning without too much hassle?
<?php
function __clone() {
foreach($this as $key => $val) {
if(is_object($val)||(is_array($val))){
$this->{$key} = unserialize(serialize($val));
}
}
}
?>
That will insure any object, or array that may potentially contain objects, will get cloned without
using recursion or other support methods.
--was--
Want deep cloning without too much hassle?
function __clone() {
foreach($this as $key => $val) {
if(is_object($val)||(is_array($val))){
$this->{$key} = unserialize(serialize($val));
}
}
}
That will insure any object, or array that may potentially contain objects, will get cloned without
using recursion or other support methods.
http://php.net/manual/en/language.oop5.cloning.php