Re: protected interface methods

From: Date: Thu, 03 Jul 2003 17:20:53 +0000
Subject: Re: protected interface methods
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-3214@lists.php.net to get a copy of this message
Hello Moriyoshi, Thursday, July 3, 2003, 7:13:44 PM, you wrote: MK> 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. MK> I see. But, is it really a matter of interface? And why don't you declare MK> an alternative duplication method rather than __clone() whose usage is MK> reserved? Clone is always there unless you hide it. And only when it is hidden object cloning is disallowed. So whatever else you declare doesn't hinder __clone from working. -- Best regards, Marcus mailto:helly@php.net

« previous php.internals (#3214) next »