Home >Backend Development >PHP Tutorial >About the difference between static and self in PHP static class static pronunciation staticlayout

About the difference between static and self in PHP static class static pronunciation staticlayout

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-29 08:53:291131browse

I have seen it once before, but I forgot the specific difference between static and self. I will review it this time.

​ static was added after PHP5.3, take a look at the English explanation:

​ self refers to the same class whose method the new operation takes place in.

​ static in PHP 5.3's late static bindings refers to whatever class in the hierarchy which you call the method on.

I have seen an article before that has a good example:

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

class B extends A {
    public static function who() {
        echo __CLASS__;
    }
}
echo B::test();

self: static method, pointing to the class that exists itself

static: pointing to the class that calls it

It’s still easy to understand, don’t forget it next time.

The above introduces the difference between static and self in PHP, including static content. I hope it will be helpful to friends who are interested in PHP tutorials.

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