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
- ext/traitify
- Traits