PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Dec 17, 2017 6:16 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Apr 08, 2015 4:37 am 
Offline
Forum Newbie

Joined: Mon Feb 15, 2010 7:01 am
Posts: 16
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 ?


Top
 Profile  
 
PostPosted: Wed Apr 08, 2015 7:12 am 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6404
Location: Montreal, Canada
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.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Wed Apr 08, 2015 11:25 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13459
Location: New York, NY, US
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)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group