Differences between Traits and Inheritance
Learn about the advantages and disadvantages of traits in comparison to inheritance.
We'll cover the following...
Trait vs. inheritance
The following is a list of properties that make traits different from inheritance:
- Traits use a form of inheritance known as horizontal inheritance. Here, the code from the trait is included in the classes in which it is used. This is similar to using
require
orinclude
functions in the classes to include code from the outside. - In a trait, it is possible to put concrete (real) methods, abstract methods, properties, and even constants.