关于self,static,$this的说明
在类中会看到 self,static,$this 调用属性和方法,但其实是有所区别的。
class test{
public function info(){
return $this;
}
}
class test1 extends test{
}
var_dump((new test)->info());
/*
class test#1 (0) {
}
*/
var_dump((new test1)->info());
/*
class test1#1 (0) {
}
*/
1、$this 和 static 代表使用者,即例子中的 test1
static可调用静态的属性和方法
$this调用非静态的
2、self 仅表示定义者,即例子中的 test
self可调用静态的属性和方法
3、new self 和 new static 也是同样的区别。
关于self,static,$this的说明
最新推荐文章于 2023-07-19 22:07:45 发布