Home > Article > Backend Development > PHP delayed static binding example analysis_PHP tutorial
This article mainly introduces PHP delayed static binding. The example analyzes the principle and implementation skills of delayed static binding. Friends who need it You can refer to the following
The example in this article describes the method of delayed static binding in PHP. Share it with everyone for your reference. The specific analysis is as follows:
php delayed static binding: refers to the self of the class, which is not based on the time of definition, but based on the running results during calculation. Let’s look at an example first
?
3 4 5 6 7 8 917 18
19
20
21
|
<🎜>header("content-type:text/html;charset=utf-8");<🎜> <🎜>class Human{<🎜> <🎜>public static function hei(){<🎜> <🎜>echo "I am the hei() method of the parent class";<🎜> <🎜>}<🎜> <🎜>public function say(){//If the subclass calls the say() method of the parent class, then <🎜> <🎜>self::hei();//What is called here is the hei() method of the parent class<🎜> <🎜>static::hei();<🎜> <🎜>//The hei() method of the subclass is called here. If the hei() method does not exist in the subclass, the <🎜> of the parent class is called. <🎜>}<🎜> <🎜>}<🎜> <🎜>class Stu extends Human{<🎜> <🎜>public static function hei(){<🎜> <🎜>echo "I am the hei() method of the subclass";<🎜> <🎜>}<🎜> <🎜>}<🎜> <🎜> <🎜> <🎜>$stu = new Stu();<🎜> <🎜>$stu->say(); ?> |