class Test{
public function test1(){
return new self();
}
public static function test2(){
return new static();
}
}
$f = new Test;
print get_class($f->test1()); //输出Test
print get_class($f->test2()); //输出Test
class Car extends Test{}
$car = new Car;
print get_class($car->test1()); //输出Test
print get_class($car->test2()); //输出Car
从以上代码测试可知,如果没有继承,那么new self()与new static()获取的结果一致,没有区别。
但是有类的继承时,new self()获取的是父类的对象,new static()获取的是当前类对象