Re: protected interface methods
| From: | Moriyoshi Koizumi | Date: | Thu, 03 Jul 2003 17:13:44 +0000 |
| Subject: | Re: protected interface methods | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-3213@lists.php.net to get a copy of this message | ||
marcus.boerger@t-online.de (Marcus Börger) wrote:
> Nice idea, but one thing i wanted is to disable cloning of class objects.
>
> The following class makes cloning impossible for all derived classes:
> class no_clone {
> final private __clone() {}
> }
>
> but the all classes that should not be cloned must be descendants from that
> class. So the following interface would disallow cloning by default, although
> it allows derived classes to reenable cloning:
> interface no_clone {
> protected function __clone()
> }
>
> When dealing with classes that handle resources such techniques are very
> helpful to prevent users from shooting themselves in the knee.
I see. But, is it really a matter of interface? And why don't you declare
an alternative duplication method rather than __clone() whose usage is
reserved?
Moriyoshi