Re: Re: Traits for PHP ... Why can't every Class be a Trait?

From: Date: Thu, 21 Feb 2008 23:44:04 +0000
Subject: Re: Re: Traits for PHP ... Why can't every Class be a Trait?
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-35714@lists.php.net to get a copy of this message
Hi, D. Dante Lorenso schrieb:
All, I can imagine a case where you would want to box common functionality into a trait and be able to use that trait as a class also. Will we end up with a lot of classes like this?: class SomeClass { use SomeTrait; } What's wrong with making all 'Class'es be 'Trait's and the only thing which makes a Trait a Trait is when you use it as such? class MyClass { trait SomeClass; } In other words, why mustn't a trait be instantiable? Why can't every Class be a Trait?
Well, the trait concept is not a silver bullet for all problems out there. What is wrong with inheritance or delegation for reusing complex behavior? Traits are for finer grained reuse in my eyes. The usage I've seen so far suggests typical traits are about 1 to 5 methods, but the average method count on a trait would be 1.88 or something like this (just a rule of thumb. from what I personally have looked at). Kind Regards Stefan

« previous php.internals (#35714) next »