Term

Trait

Meaning

A trait is a group of methods that can be reused in several unrelated classes without using inheritance. The PHP manual calls traits a mechanism for code reuse in single inheritance languages, and says a trait cannot be instantiated on its own; a class pulls it in with the use keyword. A small time-stamp feature shared by many classes is a typical case. Use traits with restraint, because hidden shared behaviour can make code harder to follow. See also: Inheritance, Interface, and the guide PHP Functions and Object Oriented Programming Concepts.

All terms