PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Refulz.com: Traits in PHP - Multiple and Nested Traits

Note: This article was originally published at PHPDeveloper on 29 May 2012.
PHPDeveloper

On the Refulz.com blog there's a new tutorial posted looking at traits (and nested traits) in PHP including examples of them in use and how to create your own.

Traits is a good new addition to PHP language. In our series about the new features of PHP 5.4, we reviewed the concept of Traits in PHP. The introductory article talks about what the traits are and what is the general syntax of Traits in PHP. The second article attempts to explain why we need traits.

The tutorial shows you how to define a custom trait use things like abstract methods, nesting them by making them "users" and how to use multiples at the same time (comma-separating).