PHP traits , is there really a reason for that ?
Moderator: General Moderators
PHP traits , is there really a reason for that ?
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 ?
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.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: PHP traits , is there really a reason for that ?
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.
(#10850)