PHP lazy Static Binding instance Analysis _php Tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.