The example in this article describes the PHP static lazy binding usage. Share to everyone for your reference, specific as follows:
PHP5.3 later introduced a deferred static binding static, what is it to solve the problem? One long-standing problem with PHP's inheritance model is that it is difficult to refer to the final state of an extended class in a 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: deferred static binding, which is the expression or variable that is fixed at the defining stage, is decided 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 is not desirable 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 Echoclass () {
echo __class__;
}
}
B::test (); Output b
The Static::echoclass () in line 8th defines a static deferred binding method until B invokes test to execute the method that was originally defined.
For more information on PHP-related content readers can view the site topics: "PHP operation Office Document tips summary (including word,excel,access,ppt)", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course", "PHP string (string) Summary of usage, Getting Started tutorial on Php+mysql database operations, and summary of common PHP database operations techniques
I hope this article will help you with the PHP program design.