`return $this;` design pattern or anti-pattern?

前端 未结 5 1574
醉酒成梦
醉酒成梦 2021-01-17 13:22

I\'ve seen many times Zend Framework using return $this; pattern style - and from my point of view:

  • Pro: seems its quite not

5条回答
  •  伪装坚强ぢ
    2021-01-17 14:01

    Returning this allows you to chain calls and set values. It is very useful for configuring some object (see Fluent interface). You can express very easily what you want (and you can use different return types to achieve what you want).

提交回复
热议问题