[TYPO3-mvc] Mixin support for Extbase 6.0

Tymoteusz Motylewski t.motylewski at gmail.com
Fri Jul 27 22:08:54 CEST 2012


Hi Claus,
Thank you for your valuable insight!
Sorry for not being clear in my previous post. I agree with you that 
using traits is a way to go, no argument here.  :)

But the problem I'm trying to solve is slightly different.
I was thinking about "opening" existing class for modification. Then the 
modified class (with mixins) would be available everywhere in the system 
under the original name.

In this case, traits are very handy (for all reasons you highlighted), 
but do not solve the problem. You still have to modify source of the 
class by applying traits or mixins.

Of course, as soon as PHP 5.4 is required by TYPO3 we can use traits 
instead of simple snippets under the hood.

Have a nice evening
Cheers
Tymek




W dniu 2012-07-27 03:14, Claus Due pisze:
> Hi Tymek,
>
> Don't take this the wrong way… I appreciate your work and efforts but I fear this is entirely redundant. I have only one vote regarding this, and that is to make PHP 5.4 a requirement and use Traits which can do exactly this.
>
> Why?
>
> Since DI uses Reflection and Reflection recognizes Traits, Traits can also contain DI methods. Traits may override methods as they wish. Traits are not bound to an Interface (but can be used by Interfaces, too!). Adding a Trait can, if I remember the docs correctly, also add an interface to a class.
>
> Traits do not require the use of code generation but still supports Reflection caching etc. Traits will not require TS, nor will they be vulnerable to TS syntax problems or inclusion sequence issues, nor will there be problems in FE/BE due to, for example, multiple root TS templates (which is a known Extbase ConfigurationManager issue, I remind you).
>
> Traits don't care about which extension they belong to, if they do or do not use namespaces or which properties they may contain. Conflicts could only arise in TCA not matching getters/setters. The programmer decides this and does this directly in his source code.
>
> Traits will work the same way in TYPO3 and FLOW3, unless FLOW3 has changed a lot since the last time I looked which is certainly a very likely possibility. Traits will not require special considerations about wether or not subclassing a class will inherit Traits used by the parent. It will. If using Traits there is no confusion about what to expect if overriding a class but intentionally not subclassing the original class.
>
> A very hard punch: Traits will not result in two files containing the same class name, which will likely cause a fatal error or inability to load the expected classes.
>
> And the last, killer argument:
>
> Traits will be recognised by IDEs and other software that reads class files. Please, please, don't choose a solution that will kill these capabilities when there is an alternative that won't.
>
> Traits is by far the better, faster, more reliable, more comfortable, easier, more efficient, less costly, more mature and more developer-friendly solution of the two. Why would anyone not prefer that?
>
> ---
>
> As you can see I'm a big fan of Traits and definitely not a fan of a reinvention of this concept, even worse in userland - further bloating an already bloated ObjectManager and in particular the inconsiderate caching implemented herein.
>
> I would like to hear any arguments against using Traits. As far as I can tell, they effectively make any considerations about mixins or multiple inheritance as an Extbase feature completely redundant. The answer will be "Why? when PHP can already do that natively and compatibly?".
>
> Unless I'm wrong?
>
> Cheers,
> Claus
>


More information about the TYPO3-project-typo3v4mvc mailing list