Re: RFC: Traits for PHP
| From: | Lars Strojny | Date: | Tue, 19 Feb 2008 22:45:14 +0000 |
| Subject: | Re: RFC: Traits for PHP | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-35623@lists.php.net to get a copy of this message | ||
Hi,
Am Montag, den 18.02.2008, 20:27 +0100 schrieb php@stefan-marr.de:
[...]
> To underpin this relationship, it is possible to declare that a Trait
> implements an interface like this::
>
> <?php
> interface IHello {
> public function sayHello();
> }
>
> trait SayHello implements IHello {
> public function sayHello() {
> echo 'Hello World!';
> }
> }
>
> class MyHelloWorld {
> use SayHello;
> }
>
> $o = new MyHelloWorld();
> var_dump($o instanceof IHello); // bool(true)
We have discussed that in IRC a bit and a lot of questions remain. The
most important issue to me how to handle interface implementations in
cases where methods from the interface implementing trait are renamed in
the trait consumer class.
I would propose to not overcomplicate things here and I see no real
advantage in allowing traits to implement interfaces. I think also for
the sake of conceptual integrity separating interfaces clearly from
traits is a good idea: interfaces define structure while traits are
function buckets. A class may use traits, may implement interfaces and
may extend another class. This paradigm is pretty easy to explain to the
user.
cu, Lars
--
Lars Strojny
Senior Software Developer MediaVentures GmbH (http://mediaventures.de)
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc
Attachment: [application/pgp-signature] Dies ist ein digital signierter Nachrichtenteil signature.asc