How to solve static binding later?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.