Re: Generic cloner?

From: Date: Thu, 08 Feb 2001 09:08:52 +0000
Subject: Re: Generic cloner?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-38724@lists.php.net to get a copy of this message
> I'm wondering if there is an easy way to code a generic cloner at top > level of object inheritance tree so that all descendents can follow? Or by > nature the clone() function needs be implemented at final class > def.? Thanks a lot! You could probably use something like: function clone($whatever){ $clone = $whatever; if (is_object($whatever)){ while (list($var, $val) = each($whatever)){ $clone->$var = clone($val); } } elseif (is_array($whatever)){ while (list($var, $val) = each($whatever)){ $clone[$var] = clone($val); } } else{ $clone = $whatever; } return $clone; } No promises this can be made to work, much less to do what you want, but it might... -- Visit the Zend Store at http://www.zend.com/store/ Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#38724) next »