MIR0720
TraitInstantiation
A trait is used with new. A trait only supplies members to the classes that use it; PHP throws Cannot instantiate trait for new Loggable(). Inside a trait, new self() and new static() name the using class and are fine.
Example
Section titled “Example”<?phptrait Loggable { public function log(string $message): void {}}
$logger = new Loggable(); // cannot instantiate traitHow to fix
Section titled “How to fix”Instantiate a class that uses the trait:
<?phpfinal class Logger { use Loggable;}
$logger = new Logger();