Re: Generic cloner?
| From: | Toby Butzon | Date: | Thu, 08 Feb 2001 23:13:22 +0000 |
| Subject: | Re: Generic cloner? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-38832@lists.php.net to get a copy of this message | ||
Umm, not sure I understand the question completely... but following the
code below, why not just assign the object to a new variable? That'd
give you an exact copy with a lot less code...
--toby
Richard Lynch wrote:
>
> > 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
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net