note 108553 deleted from language.oop5.traits by danbrown
| From: | danbrown@php.net | Date: | Thu, 10 May 2012 16:47:23 +0000 |
| Subject: | note 108553 deleted from language.oop5.traits by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-187591@lists.php.net to get a copy of this message | ||
Note Submitter: uramihsayibok at gmail dot com
----
Re: @Anonymous and
> Traits can not implement interfaces
This is true at face value: you can't
<?php
trait TInterface implements IInterface {
// implementation of IInterface's methods
}
class Example {
use TInterface;
}
?>
Conceptually it would make sense if you could do so - after all, you can put multiple interfaces on
a class. But considering how traits are implemented really more as "copy/paste" than
"multiple inheritance" it would be a hassle for PHP to support it.
The next logical step works, however. It's about having the class implement an interface by
using code from a trait.
<?php
trait TInterface {
// implementation of IInterface's methods
}
class Example implements IInterface {
use TInterface;
}
?>