in oop php what does using an arrow operator -> after a method do?
Example:
$this->getResponse()
->appendBody('Hello' . $name)
In the previous example, I un开发者_开发知识库derstand the use of the first arrow operator, but not the second, since I don't know whether what the second one does is similar to passing arguments to the function, in which case I wonder why it doesn't go inside the parenthesis.
I believe that second operator just calls appendBody()
on the object returned by $this->getResponse()
.
In other words, it's a shortcut for this:
$x = $this->getResponse();
$x->appendBody('Hello' . $name);
The same as a .
in other OOP languages: You're chaining commands together.
You call $this->getResponse()
which returns an object, then on that object you're calling appendBody()
. it'd be the same as this:
$response = $this->getResponse();
$response->appendBody('Hello'.$name);
Ironically, I was just thinking about/playing with this about 10 minutes ago.
精彩评论