"Go" late static bindings in PHP (late static Bindings)

Source: Internet
Author: User

php5.3 version of the static binding of the new static binding syntax, also become late static binding PHP, as follows

classa{ Public Static functionfunc1 () {Echo __class__.Php_eol; }     Public Static functionTest () { self::func1 (); } }classB Extend a{ Public Static functionfunc1 () {Echo __class__.Php_eol;//__class__ is the name of the current class}}b::test (); Result: A

But, since B inherits a and rewrites the func1 of a, what do you want to do with func1 in Test B? Therefore, php5.3 uses the reserved static keyword to change the test function in the above code to this:

 Public Static function Test () {        static::

结果:B

In other words: static:: The implementation of the late statically bound, static:: The corresponding variable is no longer the current class of variables, but by the final operation when the dynamic decision (also can be said from the heap extracted from the keyword).

At the same time, in this learning process, I also found another use: New Static () and new Self (), as well, new static is the instantiation of the final class, and new self is to instantiate the current class, new parent is the implementation of the current class of the parent class.

Okay, by the way. There are three ways to use this format: "Self::", "Parent::", "Static::";

"Go" late static bindings in PHP (late static Bindings)

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.