PHP Developers Network
http://forums.devnetwork.net/

PHP traits , is there really a reason for that ?
http://forums.devnetwork.net/viewtopic.php?f=19&t=141165
Page 1 of 1

Author:  jkon [ Wed Apr 08, 2015 4:37 am ]
Post subject:  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 ?

Author:  Celauran [ Wed Apr 08, 2015 7:12 am ]
Post subject:  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.

Author:  Christopher [ Wed Apr 08, 2015 11:25 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/