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
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。