Introduction

PHP is growing up fast. There has been a major push from the folks at Zend (the company that maintains PHP), and this focuses on two major concerns; security, and the object oriented aspects of the language. We've come a long way from PHP 4, which introduced a very simple and shaky object oriented interface for developers to play with. But PHP 5 changed that, and with every increment of the PHP 5 version, we are being given a great deal more functionality, as well as a new level of maturity.

 

What's new? Let's check out a few of the new features.

Traits have been added to PHP for a very simple reason: PHP does not support multiple inheritance. Simply put, a class cannot extends more than on class at a time. This becomes laborious when you need functionality declared in two different classes that are used by other classes as well, and the result is that you would have to repeat code in order to get the job done without tangling yourself up in a mist of cobwebs.

 

Enter traits. These allow us to declare a type of class that contains methods that can be reused. Better still, their methods can be directly injected into any class you use, and you can use multiple traits in the same class. Let's look at a simple Hello World example.