PHP Static latency static binding usage analysis, Static static
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.