note 108553 added to language.oop5.traits
| From: | uramihsayibok at gmail dot com | Date: | Sun, 06 May 2012 10:09:35 +0000 |
| Subject: | note 108553 added to language.oop5.traits | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187491@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 208.69.120.55
Probable Submitter: 67.160.103.222
----
Manual Page -- http://www.php.net/manual/en/language.oop5.traits.php
Edit -- https://master.php.net/note/edit/108553
Del: integrated -- https://master.php.net/note/delete/108553/integrated
Del: useless -- https://master.php.net/note/delete/108553/useless
Del: bad code -- https://master.php.net/note/delete/108553/bad+code
Del: spam -- https://master.php.net/note/delete/108553/spam
Del: non-english -- https://master.php.net/note/delete/108553/non-english
Del: in docs -- https://master.php.net/note/delete/108553/in+docs
Del: other reasons-- https://master.php.net/note/delete/108553
Reject -- https://master.php.net/note/reject/108553
Search -- https://master.php.net/manage/user-notes.php