因为我们知道代码包含在函数中,所以需要这个$this吗?


Is this $this needed since we know the code is contained within the function

如果$this引用了它自己的类实例。如果省略它会有什么不同吗?因为我们知道'$this'是什么引用,因为它总是在创建的实例中。

Class examp {
Public Function getName($name) {
$this->$name=name; 
}

。$this省略

Class examp {
Public Function getName($name) {
$name=name;
}

在第一个例子中,$this->name将永远不会指向参数,因为您显式引用当前对象$this的属性name

对于第二个示例,您只是引用参数,这种差异是使用/省略$this的原因之一。