About static binding at a later time, how to solve

Source: Internet
Author: User
About late static bindings
Read the PHP manual about the late static binding, or not quite understand, the original address http://cn2.php.net/manual/zh/language.oop5.late-static-bindings.php

A fourth example
PHP Code
  
   
  
   

The result is:
A
C
C
When calling to Parent::foo () and Self::foo (), why would I call the WHO () of Class C?
Which friend can explain, thank you.

------Solution--------------------
Explanation of the static operator:
late static binding attempts to bypass the restriction by introducing a keyword that represents the class that was originally called by the runtime.
And the class that was originally called is C.

A::foo (); Called a Class A method, which you understand
Self::foo (); This self is actually class C. Do you understand? C::test () c inherits the test () method of B
Parent::foo (); Due to static::who (); Rather than self::who (). The method calls the current class, which is the Foo () method of Class C

Maybe you still don't understand the WHO () method in Class A and why not call C, which is due to the special relationship of the parent. Lazy static binding is the only problem that occurs when you specifically resolve the inheritance method between subclasses and parent classes.
------Solution--------------------
It's not a very clear manual, is it?
------------------------------------------------------
Late binding means that static:: It is no longer parsed to define the class in which the current method resides, but is calculated at the actual run time. It can also be called a "static binding" because it can be used (but not limited to) the invocation of a static method.
-------------------------------------------------------

#1说的有个小问题

PHP Code
  • 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.