Static binding usage Analysis for PHP static lazy, static statically
This example describes the static binding usage of PHP static delay. Share to everyone for your reference, as follows:
PHP5.3 later introduced the lazy static binding static, which is to solve what problem? One of the long-running problems with the PHP inheritance model is that it is difficult to refer to the final state of the extended class in the parent class. Take a 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 A
A new feature has been added to the PHP5.3: lazy static binding, which is the expression or variable that was fixed at the definition stage, is determined at the execution stage, such as when a subclass inherits the static expression of the parent class, its value cannot be changed, and sometimes it does not want to see it.
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 EC Hoclass () { echo __class__; }} B::test (); Output b
The 8th Line of Static::echoclass () defines a static delay binding method until B executes the method that was originally defined when the test was called.
More readers interested in PHP related content can view this site topic: "PHP Operations Office Document Tips summary (including word,excel,access,ppt)", "PHP date and Time usage summary", "PHP Object-oriented Programming tutorial", "PHP string (string) Usage summary, "Getting Started with Php+mysql database operation" and "PHP common database Operation Skills Summary"
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- Simple Talk about PHP lazy static binding
- PHP lazy Static Binding instance analysis
- PHP lazy static Binding sample sharing
- Turn on the PHP Static keyword Travel mode
- static property and static method of PHP
- The Static keyword in PHP and the difference from the Self keyword
- PHP Object-oriented tour: in-depth understanding of static variables and methods
- An analysis of the use of PHP variable modifier static
- Analysis of the difference between static,const and define in PHP
- The static and static variable usage of the PHP class is described
http://www.bkjia.com/PHPjc/1111342.html www.bkjia.com true http://www.bkjia.com/PHPjc/1111342.html techarticle Static binding usage analysis of PHP static delay, statically static This article describes the static binding usage of PHP static delay. Share to everyone for your reference, specifically as follows: PHP5.3 later introduced ...