Page 1 of 1
PHP traits , is there really a reason for that ?
Posted: Wed Apr 08, 2015 4:37 am
by jkon
I seriously dislike PHP traits ... I can find any other use of it other than “I don't want to write OOP but I pretend I do” am I wrong , is there any real use of it ?
Re: PHP traits , is there really a reason for that ?
Posted: Wed Apr 08, 2015 7:12 am
by Celauran
I actually find traits to be immensely useful. Think of them as interfaces with implementation. Because PHP only supports single inheritance, traits often allow you to keep your code DRY when disparate classes extending the same parent class just wouldn't make sense.
Re: PHP traits , is there really a reason for that ?
Posted: Wed Apr 08, 2015 11:25 pm
by Christopher
I agree with Celauran, traits are a DRY way to implement multiple inheritance. They are a structured way to promote code reuse and standardize the implementation common functionality across classes. I'd much rather use traits than resort to very abstract base classes like Object to provide a common interface to many related classes.