RE: [PHP-DEV] Revisit: Traits requiring composing class to implement interface
| From: | Jonathan Bond-Caron | Date: | Sat, 22 Oct 2011 18:27:42 +0000 |
| Subject: | RE: [PHP-DEV] Revisit: Traits requiring composing class to implement interface | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-55906@lists.php.net to get a copy of this message | ||
On Sat Oct 22 10:25 AM, Anthony Ferrara wrote:
> Well, I have a few opinions on this that I think are worth sharing:
>
> 1. If this change is made, we no longer would have mixins, but would
> have regular multiple-inheritance (With all the "issues" associated
> with it). Note that I said mixins and not traits. That's because
> since these were implemented with state (member properties), they are
> not traits as implemented, but regular mixins. (Yet another gripe, but
> that's slightly off topic).
>
I think you misunderstand the difference between traits and mixins:
http://code.google.com/p/es-lab/wiki/Traits
Scala has mixins, php has traits.
In short, the composition order does not matter with a trait (because there are conflict resolution
rules).
With a mixin, the conflict resolution rule is the order of declaration. class foo mixwith bar1,
bar2 {} // bar2 wins
Though traits were originally defined as 'stateless', it doesn't make them
'mixins' because they have state:
http://bergel.eu/download/papers/Berg07e-StatefulTraits.pdf
Javascript is probably the best example of 'mixins':
myobject.mixin(bar1,bar2, {otherMethod: function(){} })