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?, The difference between Traits, Interfaces, and Abstract Classes in PHP
Related : Class, Class Interface Trait Enumeration (CITE), Use