Re: __clone() implementation

From: Date: Mon, 02 Feb 2004 18:18:44 +0000
Subject: Re: __clone() implementation
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-7477@lists.php.net to get a copy of this message
== Quote from Zeev Suraski (zeev@zend.com)'s article > Andi and I have revisited the __clone() implementation and must agree that > it wasn't quite right (mainly due to it not working with inheritance). > We have rewritten it now (major change!!!) because we didn't want PHP 5 to > be released with a fundamentally flawed mechanism. > Zeev, Sounds good. However let me precise some troubles with the new implementation. 1/ Imagine a class with members, but it does not implement __clone because the bit for bit copy is OK. Now you derive this class and you need to implement __clone. Because the first class does not implement it, you can't call parent::__clone (I assume). So this is the responsibility of the derived class to clone the base class. This is not only not clean, but private members won't be visible. 2/ It still does not help what I already mentioned: when a class implements __clone(), all its derived classes have also to implement it to transfer their own members. For sure, in these 2 cases there are work arounds: * case 1: modify the base class to implement __clone, * case 2: implement __clone in the derived classes. Another idea for case 1 could be to be able to call parent::__clone even if the class does not implement it and have the bit for bit copy (but just for the base class). Regards, Stephane

« previous php.internals (#7477) next »