Home > Backend Development > PHP Tutorial > Detailed description of php static binding

Detailed description of php static binding

韦小宝
Release: 2023-03-21 11:10:01
Original
1284 people have browsed it

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 ();
Copy after login

Result:

// A
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template