News Archive
PhpRiot Newsletter
Your Email Address:

More information

Refulz Blog: Traits in PHP 5.4 - Why we need Traits

Note: This article was originally published at PHPDeveloper on 31 March 2012.

On the Refulz blog today there's a new post about traits in PHP (recently introduced in PHP 5.,4) and why we need them in our development.

Traits is one major addition to PHP. We read an introductory article about Traits in PHP 5.4. In the post, we saw an example code which only resembles single inheritance. So, what is the actual purpose of Traits and why do we need to use Traits in our code.

They give a sample use case involving two types of clients, Business and Individual, and how you can use a single Client class and trait to provide address-related functionality.