[Phpug] Traits in PHP, your opinions
Michał Słaby
michal.slaby at epsi.pl
Tue Feb 19 17:16:30 GMT 2008
On Tue, 2008-02-19 at 11:00 -0500, David Coallier wrote:
> Hello all,
>
> Yesterday a proposal has been made on the internals php list
> (http://news.php.net/php.internals/35562) about the having "traits" in
> PHP.
Hi David,
I am not internals subscriber, but I have some thoughts on this
construct. I am absolutely sure that Traits may be useful for some
developers, but is there a task that can be solved by Traits and not by
proper object model? I went though RFC quickly and I found that the
actual reason for Traits is to make bad developers feel better.
> For those who are unfamiliar with "traits", it's basically a solution
> around multiple inheritance for single inheritance languages as such
> as PHP. It's basically a nice word for "code reuse". It already exists
> in languages as such as Perl, Java, C# and now, proposed for php.
Is it only my impression that PHP is trying to be more dynamic than Ruby
is? ;-)
> You can read the proposal here:
> http://www.stefan-marr.de/artikel/rfc-traits-for-php.html and you can
> see many examples to enlighten your questions, and for the most
> adventurous of you, you can even read the thesis at the end (which I
> recommend, quite good).
>
> Thoughts ?
>From my point of view, the need for Traits is a clear signal to refactor
object structure. Some functionalities should be delegated to other
classes, which conforms the general consensus that delegation and
composition is usually better than inheritance.
Correct me if I'm wrong, but there are Implementation Classes in UML
which are neither classes nor interfaces (they contain implementation
but cannot be intantiated, pretty much like Traits).
I'll better go through the dissertation. ;-)
Regards,
Michael
More information about the Phpug
mailing list