Trait¶
Traits are a mechanism for code reuse in single inheritance languages.
Traits define methods and properties. They are included in one or several classes by the use of use expression.
<?php
trait T {
const CONSTANT = 1;
private $property;
function method() {}
}
class x {
use t;
}
?>
See also Traits are not inherited, What are traits, Some lesser known facts of Traits in PHP, When to use a trait? and The difference between Traits, Interfaces, and Abstract Classes in PHP.
Related : Class, Class Interface Trait Enumeration (CITE), Use, $this, Const, Constants In Trait, Use In Traits, Method Collision, Method, Method Resolution Order (MRO), Polymorphism