关于new self 和 new static的区别
在类的定义中实例化自己的三种方式:
class test{
function info(){
$my1 = new self;
$my2 = new static;
$my3 = new test;
}
}
其中
new self 和 new test 是一样的,得到的对象永远都是 test类的实例
new static方式得到的对象却不一定是 test类的实例,例如:
class test1 extends test{
}
test1 继承 test ,info方法被继承,此时 test1->info 返回的就是 test1类的实例,这样在一定程度要安全一些。
关于new self 和 new static的区别
最新推荐文章于 2022-05-12 17:40:51 发布