Return by reference in PHP

后端 未结 3 1604
礼貌的吻别
礼貌的吻别 2020-12-14 06:23

I tried Googling, tried PHP Documentation, searched Stack Overflow for an answer but couldn\'t find anything satisfactory. I was reading a book in which author have made use

3条回答
  •  轮回少年
    2020-12-14 07:02

    The example you posted is probably from PHP4 or earlier. It's no longer necessary to return objects by reference as they are almost always done that way automatically in PHP5+.

    Returning by reference is useful when you want to use a function to find to which variable a reference should be bound. Do not use return-by-reference to increase performance. The engine will automatically optimize this on its own. Only return references when you have a valid technical reason to do so.

    See return references in PHP docs

提交回复
热议问题