You are here: Re: [PHP] interfaces - your opinion « PHP « IT news, forums, messages
Re: [PHP] interfaces - your opinion

Posted by Jochem Maas on 12/30/05 14:38

hi Marco,

I want to apply the idea to interface implementation not
class extension. that is to say I want to be able to make an
interface only implementable by certain (defined) classes (and their
subclasses) with out imposing any restriction on the classes
themselves (like that they must extend a certain base class in order
to have the 'implementable by' check performed.

IFAICT this is not really possible - but maybe somebody sees a way,
then again maybe it's too silly an idea to even consider it.
regardless thanks for your feedback.

rgds,
jochem

Marco Kaiser wrote:
> Hi Jochem,
>
> try this.
>
> <?php
>
> abstract class AClass
> {
> private $allowedClasses = array(
> 'MyClass',
> 'MyOtherClass'
> );
> final public function __construct()
> {
> if (!in_array(get_class($this), $this->allowedClasses)) {
> throw new Exception('not allowed classes: ' . __CLASS__);
> }
>
> // if (($this instanceof MyClass) ||
> // ($this instanceof MyOtherClass)) {
> // throw new Exception('not allowed class: ' . __CLASS__);
> // }
> }
> }
>
>
> class MyClass extends AClass {}
>
> class MyOtherClass extends AClass {}
>
> class NotMyClass extends AClass {}
>
> new MyClass();
> new MyOtherClass();
> new NotMyClass();
>
>
> --
> Marco Kaiser

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация