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