Analysis of php delayed static binding instances. Analysis of php delayed static binding instances this article mainly introduces php delayed static binding. the instance analyzes the principles and implementation skills of delayed static binding, for more information, see the following example: php latency static binding instance analysis.
This article mainly introduces php delayed static binding. the instance analyzes the principle and implementation skills of delayed static binding. For more information, see
This article describes how to delay static binding in php. Share it with you for your reference. The specific analysis is as follows:
Php delayed static binding: refers to the class self, which is not defined at the time of definition, but the running result at the time of calculation. First look at an instance
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 Self: hei (); // The hei () method of the parent class is called here. Static: hei (); // The hei () method of the subclass is called here. if the subclass does not have the hei () method, } } Class Stu extends Human { Public static function hei (){ Echo "I am the hei () method of the subclass "; } } $ Stu = new Stu (); $ Stu-> say (); ?> |
Note:
(1) when the subclass instantiate object $ stu calls the say method, it runs in the parent class Human. Therefore, self: hei () in say () is to call the hei () method of the parent class.
(2) static: method name (): If you use the static keyword, you first need to find the method in the subclass. if you cannot find the method, you can find it in the parent class.
I hope this article will help you with php programming.
This article introduces php delayed static binding. the instance analyzes the principle and implementation skills of delayed static binding. For more information, see the following example...