I just asked a question about Traits
and I had another question.
If Traits
are mechanisms that facilitate the import of methods, because of the limitations of an inheritance in PHP, why can their methods be accessed statically?
For example:
trait Stack
{
protected $items = [];
public static function say()
{
return 'stack';
}
}
echo Stack::say(); // stack
Is not this confusing considering the meaning of trait
implementation in language?
Is it recommended to use a static method from a trait
, or is it better to use it in a class?