New to PHP 5.4: Traits
New to PHP 5.4: Traits – Simas Toleikis.
Really geeking out at the fact that PHP 5.4 includes traits. If you’re not familiar with traits, they’re a method of inheritance somewhat like extending classes. Simas does a great job of explaining the intimate details of traits in PHP 5.4, so I’ll leave it at my excitement about using something like this soon(ish):
trait Singleton {
public static function getInstance() { ... }
}
class A {
use Singleton;
// ...
}
class B extends ArrayObject {
use Singleton;
// ...
}
// Singleton method is now available for both classes
A::getInstance();
B::getInstance();
Sweet.