LoggerTrait: The Good (or Bad) approach to Logging
4 min readJan 5, 2020
What is a Trait?
They allow incorporating inside another class any group of methods, inside some categorization, the Trait.
Similar to an abstract class, but with a great difference: it cannot be instantiated on its own.
In PHP they were introduced to be an instrument for code reuse because PHP is a single inheritance language.
And in PHP they have the following characteristics:
- You can define properties.
- You can define constructors.
- You can define abstract methods.
- It does not support inheritance.
- Traits are not types.
- It is not possible to instantiate on its own.
Is a Good or Bad practice?
There is a lot of controversy about Traits, being considered by many, like a bad practice.
Benjamin Eberlei on his blog considered him as static access. Others, that they are a kind of automated copy-paste code.