PHP new self()和new static()的区别

new static()是php5.3以后引入新的特性,延迟静态绑定.访问的是当前实例化的那个类,那么 static 代表的就是那个类。

new self() 是指的不是调用上下文,它指的是解析上下文.

class  Test {

    public static funtion getSelf(){

            return new self();

     }

    

    public static funtion getStatic(){

            return new static();

     }

  }

class  Test1 extends Test {


  }

echo get_class(Test1 ::getSelf);  输出:Test 

echo get_class(Test1 ::getStatic);输出:Test1 

echo get_class(Test ::getStatic);输出:Test