Select Page

Was double-checking this today and confirmed that PHP does not support derivation from multiple classes.  But worthy of writing this article was a new construct introduced in PHP 5.4: traits.

Traits mostly remind me old-school C pre-processor #define calls.  So, I can do something like this:

[dt_code]

trait A
{
public function X() { echo ‘X’; }
}

class B
{
use A;
}

A a = new A();
a.X();

[/dt_code]

Mix this with inheritance and interfaces – wow!

Official PHP docs: