What does “return $this” mean?

前端 未结 7 449
遇见更好的自我
遇见更好的自我 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:02

    This way of coding is called fluent interface. return $this returns the current object, so you can write code like this:

    $object
      ->function1()
      ->function2()
      ->function3()
      ;
    

    instead of:

    $object->function1();
    $object->function2();
    $object->function3();
    

提交回复
热议问题