hujh20 发表于 2018-12-13 10:06:57

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

  new static()是php5.3以后引入新的特性,延迟静态绑定.访问的是当前实例化的那个类,那么 static 代表的就是那个类。
  new self() 是指的不是调用上下文,它指的是解析上下文.
  classTest {
  public static funtion getSelf(){
  return new self();
  }

    public static funtion getStatic(){
            return new static();
   }
  }

classTest1 extends Test {


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



页: [1]
查看完整版本: PHP new self()和new static()的区别