This article mainly introduces the usage of PHPStatic delayed Static binding, and analyzes the Static delayed Static binding functions, definitions, and usage skills in combination with the instance form, for more information about Static binding with PHP Static latency, see the example in this article. 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.