PHP lazy Static Binding instance analysis
This article mainly introduces the PHP delay static binding, the example analyzes the delay static binding principle and implementation skills, the need for friends can refer to the following
The example in this article describes how PHP delays static binding. Share to everyone for your reference. The specific analysis is as follows:
PHP lazy Static binding: Refers to the self of the class, not as defined, but rather as the result of the operation of the calculation. Look at an example first
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21st |
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, the Self::hei ();//The Hei () method of the parent class is called here Static::hei (); The Hei () method of the subclass is called here, and if the subclass does not have the HEI () method, the parent class is called } } Class Stu extends human{ public static function Hei () { echo "I am the Hei () method of the sub-class"; } } $stu = new Stu (); $stu->say (); ?> |
Description
(1) When a subclass instantiates an object $stu calls the Say method, it runs within the parent class human, so Self::hei () in Say () is the HEI () method that invokes the parent class.
(2) Static:: Method Name (): Use the static keyword, the first is to find the method in the subclass, if not found, then find in the parent class.
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/955271.html www.bkjia.com true http://www.bkjia.com/PHPjc/955271.html techarticle PHP delay Static Binding instance analysis This article mainly introduces the PHP delay static binding, the example analysis of the delay static binding principle and implementation skills, the need for friends can refer to the example of this article ...