请解释一下,对于什么$this
和->
代表...让我们举例说明以下代码......
$this->convertNamesToCaptions($order, $formId)
Run Code Online (Sandbox Code Playgroud)
Bon*_*ono 14
$ this指的是当前对象
手册说:
当从对象上下文中调用方法时,伪变量$ this可用.$ this是对调用对象的引用(通常是方法所属的对象,但如果从辅助对象的上下文中静态调用该方法,则可能是另一个对象).
小例子:
class Test
{
private $var;
public function func()
{
$this->var = 1;
return $this->var;
}
}
$obj = new Test();
$obj->func();
Run Code Online (Sandbox Code Playgroud)