关于PHP中static和self的区别

来源:互联网 发布:淘宝兼职画师 编辑:程序博客网 时间:2024/05/14 03:11

     之前看过一次,但是忘了static和self的具体区别了,这次在复习一下。

     static是PHP5.3之后加进来的,看一下英文的解释:

    

     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.

     之前看过一个文章这个例子很好:

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:指向调用它的类

还是很容易理解的,下次不能再忘了。

0 0
原创粉丝点击