A trait is copied into the using class at compile time, so self, static and __CLASS__ all refer to the class rather than to the trait.
trait Loggable
{
public function channel(): string
{
return static::class; // the using class
}
}
final class OrderImporter { use Loggable; }
(new OrderImporter())->channel(); // 'OrderImporter'
// and the one that differs: a trait CONSTANT cannot be
// read through the trait name at all.
This is what makes a trait usable for anything that needs to know its host — a log channel, a cache key prefix, a table name — and it is the property that distinguishes a trait from a base class in practice. The copy semantics also mean a trait method is not in the inheritance chain, so a parent class method of the same name is overridden by the trait rather than the reverse.