[英]in oop php what does using an arrow operator -> after a method do?
例:
$this->getResponse()
->appendBody('Hello' . $name)
在上一個示例中,我了解第一個箭頭運算符的用法,但不了解第二個箭頭運算符的用法,因為我不知道第二個箭頭運算符的作用是否類似於將參數傳遞給函數,在這種情況下,我想知道為什么不這樣做?不要放在括號內。
我相信第二個運算符只是在$this->getResponse()
返回的對象上調用appendBody()
$this->getResponse()
。
換句話說,這是一個捷徑:
$x = $this->getResponse();
$x->appendBody('Hello' . $name);
與相同.
在其他OOP語言中:您正在將命令鏈接在一起。
您調用$this->getResponse()
返回一個對象,然后在該對象上調用appendBody()
。 會是這樣的:
$response = $this->getResponse();
$response->appendBody('Hello'.$name);
具有諷刺意味的是,大約10分鍾前,我只是在考慮/玩這個游戲。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.