At 20:18 02/02/2004, Stephane Drouard wrote:
== Quote from Zeev Suraski ([EMAIL PROTECTED])'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).

Both are valid points, and they both sound like the same problem from two different angles. I think that the best approach would be to first do an implicit clone (i.e., 'dumb' copy of all of the elements), and then call __clone(), even if it exists. It should solve both cases.


Zee

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to