Home  >  Article  >  Backend Development  >  Late static binding in php

Late static binding in php

不言
不言Original
2018-07-09 17:45:101220browse

This article mainly introduces the late static binding of PHP, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Starting from PHP 5.3.0, PHP has added a feature called late static binding, which is used to reference statically called classes within the inheritance scope. This is the official explanation of PHP, that is, during the inheritance process of a class, the class used is no longer the current class, but Calling class.

Late static binding is implemented using the keyword static. Through this mechanism, "static::" is no longer resolved to the class in which the current method is defined, but is calculated during actual runtime. The result obtained is the class initially called at runtime.

Although it is called "late static binding", it is not limited to calls to static methods.

class A{
    public static function call(){
        echo "class A<br/>";
    }
    public static function test(){
        self::call();
        static::call();
    }
}
class B extends A{
    public static function call(){
        echo "class B";
    }
}

echo (B::test());
//输出结果:
//class A
//class B

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

PHP simply implements sending emails and preventing them from being treated as spam

How to use PHP arrays

The above is the detailed content of Late static binding in php. 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