PHPStatic latency static binding usage analysis, static _ PHP Tutorial

Source: Internet
Author: User
PHPStatic latency static binding usage analysis, static. PHPStatic latency static binding usage analysis. static this article describes PHPStatic latency static binding usage. For your reference, see PHP5.3 and later introduction of PHP Static latency static binding usage analysis.

This article describes the usage of Static binding with PHP Static latency. We will share this with you for your reference. The details are as follows:

After PHP5.3, static binding with latency is introduced. what problems does PHP5.3 solve? The inheritance model of php has a long history problem, that is, it is difficult to reference the final state of the extension class in the parent class. Let's look at an example.

Class A {public static function echoClass () {echo _ CLASS __;} public static function test () {self: echoClass ();}} class B extends A {public static function echoClass () {echo _ CLASS __;}} B: test (); // output

Added a new feature in PHP5.3: delayed static binding is to change the expressions or variables originally fixed in the definition stage to the execution stage, for example, when a subclass inherits the static expression of the parent class, its value cannot be changed. sometimes you do not want to see this situation.

The following example solves the problem raised above:

Class A {public static function echoClass () {echo _ CLASS __;} public static function test () {static: echoClass ();}} class B extends A {public static function echoClass () {echo _ CLASS __;}} B: test (); // output B

The static: echoClass (); of the 8th rows defines a static latency binding method, which is executed only when B calls test.

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.