Why can Traits have directly called methods when they are static?

4

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?

    
asked by anonymous 24.02.2015 / 16:45

1 answer

3

After reading on this site , I understood the following:

  • Members (fields and / or methods) coming from a trait have a higher priority than those coming from a super class, but smaller than those from the current class.
  • When two different classes use the same trait , static members of trait are different for each of the classes.
  • And there are other things about traits on the linked site, if you have more questions.

        
    24.02.2015 / 18:00