在oop php中使用箭头操作符 - >一个方法后做什么?

the*_*sis 1 php oop

例:

$this->getResponse()
     ->appendBody('Hello' . $name)
Run Code Online (Sandbox Code Playgroud)

在前面的例子中,我理解第一个箭头操作符的使用,但不是第二个,因为我不知道第二个操作符的作用是否与向函数传递参数类似,在这种情况下我想知道它为什么没有进入括号内.

Dan*_*n J 8

我相信,第二运营商只是调用appendBody()该对象返回$this->getResponse().

换句话说,它是一个捷径:

$x = $this->getResponse();
$x->appendBody('Hello' . $name);
Run Code Online (Sandbox Code Playgroud)

  • 也称为方法链 - > http://en.wikipedia.org/wiki/Method_chaining (6认同)