About the late static binding to see the php Manual on the Late static binding, still do not understand, the original address cn2.php. netmanualzhlanguage. oop5.late-static-bindings.php of which the fourth example PHPcode & lt ;? PhpclassA {publicstaticfunctionfoo () {s about static binding later
I saw the php Manual on the Late static binding, still do not understand, the original address http://cn2.php.net/manual/zh/language.oop5.late-static-bindings.php
The fourth example
PHP code
The result is:
A
C
C
When calling parent: foo () and self: foo (), why does it call who () of Class C ()?
Which of you can explain? thank you.
------ Solution --------------------
Explanation of the static operator:
Later static binding attempts to bypass the restriction by introducing a keyword to indicate the class initially called during the runtime.
The class originally called is C.
A: foo (); the method of Class A is called, which you understand
Self: foo (); // The self is actually a C class. Do you understand? C: test () C inherits the test () method of B.
Parent: foo (); // because static: who (); instead of self: who (). The current class called by this method, that is, the foo () method of class C.
Maybe you still don't understand why class A didn't call C's who () method. this is due to the special relationship of parent. Delayed static binding is designed to solve the problem of inheritance methods between child classes and parent classes.
------ Solution --------------------
Isn't the manual clear?
------------------------------------------------------
"Post-binding" means that static: is not resolved to define the class of the current method, but calculated during actual operation. It can also be called "static binding" because it can be used for (but not limited to) calling static methods.
-------------------------------------------------------
#1 there is a small problem
PHP code
Self: foo (); // The self is actually a C class. Do you understand? C: test () C inherits the test () method of B.