News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Allan MacGregor:
Exploring Traits
March 17, 2014 @ 11:48:59

In his new post Allan MacGregor takes a look at a somewhat underused feature of PHP (since 5.4), traits. He talks about how they can help solve multiple inheritance issues and the power they can offer.

Languages like C++ or Python manage this problem by allowing inheritance from multiple classes, Ruby in the other hand uses Mixings to address this issue. Regardless of the technique the problem remains the same; Traits are another approach to this problem and are commonly used in the languages like Perl and Scala.

He includes an example of the standard PHP method for inheritance in classes via the normal "extends" handling. He refactors this into a setup using traits to "override" the single inheritance issues via a "Cat" trait included in the "Tiger" class providing the "roar" method inside the class context.

The best part about traits is that it makes sense from a structural point of view. [...] Traits are an incredible addition to the PHP language and we have only started to touch the surface.
0 comments voice your opinion now!
traits introduction multiple inheritance

Link: http://coderoncode.com/2014/03/17/exploring-traits.html

blog comments powered by Disqus

Similar Posts

Community News: Latest PEAR Releases for 08.30.2010

Community News: Latest Releases from PHPClasses.org

ZendCasts.com: Writing Composite Zend_Form Elements

Community News: Latest PEAR Releases for 02.11.2013

NetTuts.com: Simplify Form Handling in a Big Way


Community Events





Don't see your event here?
Let us know!


security composer artisanfiles laravel version tool library release framework interview introduction language series symfony community conference podcast opinion voicesoftheelephpant list

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework