What does “return $this” mean?

前端 未结 7 419
遇见更好的自我
遇见更好的自我 2020-12-13 00:34

I\'m trying to understand this code, and when I arrived at the final line, I didn\'t get it. :(

Can I have your help in order to find out, what does re

7条回答
  •  时光说笑
    2020-12-13 01:18

    $this means the current object, the one the method is currently being run on. By returning $this a reference to the object the method is working gets sent back to the calling function.

    So anyone doing

     $foo2 = $foo->SetOptions($bar);
    

    $foo2 now refers to $foo also.

提交回复
热议问题