Re: protected interface methods
| From: | Moriyoshi Koizumi | Date: | Thu, 03 Jul 2003 16:50:46 +0000 |
| Subject: | Re: protected interface methods | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-3210@lists.php.net to get a copy of this message | ||
marcus.boerger@t-online.de (Marcus Börger) wrote:
> Not really. An interface simply describes a protocol subset that must be part
> of the implementing class's protocol. In that it makes no sense to allow final
> or private methods in an interface but still a protected member in an interface
> would describe a subset of a protocol. And hence it would describe a method
> that must be available with protected or public visibility. Or in other words
> it would make it possible to hide a method per default from outside.
>
> "A derived class must implement it but other classes are not supposed to use
> it"
>
> I came across this when i experimened with __clone.
I don't know what you experienced with __clone exactly, but maybe you
wanted the class to allow accesses only from instances that have the same
interface as the one being invoked. If so, my suggestion is to let those
methods take a parameter that holds a caller instance and filter the
accesses to it by the condition applying "instanceof" operator to that
instance.
p.s. A predefined variable like "$that" which indicates the caller
instance would be what you want?
Moriyoshi