Why the User model uses late static binding?

Good afternoon, help to understand with a question of how the mechanism of late binding in a User model, which is described in Yii2 advanced? How does the chain of inheritance in the expression static::findOne and in what context a function findOne the result will be made? I understand that the static keyword creates a reference to the context of the User class? And if the interpreter does not find the implementation of the method findOne he goes farther up the inheritance chain?
June 14th 19 at 20:35
1 answer
June 14th 19 at 20:37
Solution
help to deal with the question of how the mechanism of late binding in a User model, which is described in Yii2 advanced?

in the same way as in PHP
How does the chain of inheritance in the expression static::findOne and in what context a function findOne the result will be made?

the interpreter checks the method in the current class if it does not exist occurs check/calling a method further down the inheritance hierarchy
Maxim, thanks for the reply, but what is the advantage of using late binding in User in the form, as implemented in Yii2 in the example? Why is this solution used? Or so wanted the authors? - Gay69 commented on June 14th 19 at 20:40
generally it is always better to use late binding instead of self, for example in Your User model can be implemented findOne method locates a user given his activity, lock status and other necessary settings. Actually late binding and allows you to provide overriding methods. - bryana.Renn commented on June 14th 19 at 20:43
ok, now I see. This is done with the intention that "I" was able to determine its same static function. I understand that if I am in my User model declared some static function findOne, I can use it as ID, self:: and static ID::.
I just confused the ID of static:: in a child class I thought it logical to define in the parent class. But then I realized that the method-you still need to call in any context, i.e. it is necessary to put self, but if you put self::, it is necessary to implement the method in the same class, otherwise the interpreter will throw an error, and if the method you want to override (so as not to duplicate code), you just need to put static::, the interpreter will go to look for this method in the hierarchy.... If I lied, please correct. - Gay69 commented on June 14th 19 at 20:46

Find more questions by tags Yii