他们的区别只有在继承中才能体现出来、如果没有任何继承、那么二者没有任何区别
然后 new self() 返回的实列是不会变的,无论谁去调用,实例化的是new self () 当前所在的类
而 new static则是由调用者决定的。哪个类的实例化去调用 new static () 那么实例化的就是调用者的类
class Father
{
public function getNewFather()
{
return new self();
}
public function getNewCaller()
{
return new static();
}
}
class Sun1 extends Father
{
}
$sun1 = new Sun1();
var_dump($sun1->getNewFather()); // object(Father)#4 (0) { }
var_dump($sun1->getNewCaller()); // object(Sun1)#4 (0) { }