Home  >  Article  >  Backend Development  >  Detailed description of php static binding

Detailed description of php static binding

韦小宝
韦小宝Original
2018-03-14 12:44:511141browse

This article briefly describes static binding in PHP. Students who are not familiar with static binding in PHP can take a look at this article about static binding in PHP!

Late static bindingThe working principle is to store the class name in the previous "non-forwarding call" (non-forwarding call).

  • When making a static method call, the class name is the one explicitly specified (usually on the left side of the :: operator );

  • When a non-static method call is made, it is the class to which the object belongs.

The so-called "forwarding call" (forwarding call) refers to the static call made in the following ways: self::, parent::, static:: and forward_static_call(). You can use the get_called_class() function to get the class name of the called method, and static:: points out its scope.

Limitations of self::

Use self:: or CLASS a static reference to the current class , depending on how the current method is defined Category:

Example:

class  A  {
    public static function  who () {
        echo  CLASS ;
    }
    public static function  test () {
         self :: who ();
    }
}

class  B  extends  A  {
    public static function  who () {
        echo  CLASS ;
    }
}

B :: test ();

Result:

// A

The above describes all the contents of this article. Everyone must feel confused after reading it. I hope You can read more with examples and implement two of them yourself!

related suggestion:



PHP Late Static Binding Example Sharing

PHP Post OOP Post Static Binding

The above is the detailed content of Detailed description of php static binding. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn