When to pass-by-reference in PHP

后端 未结 5 556
慢半拍i
慢半拍i 2020-11-27 04:45

Im wondering if its good practice to pass-by-reference when you are only reading a variable, or if it should always be passed as a value.

Example with pass-by-refere

5条回答
  •  臣服心动
    2020-11-27 05:31

    The joy of micro-optimisation. :-)

    To be honest, there's probably not a great deal to be gained by passing 'normal' variables by reference (unless you want to affect their value in their original scope). Also, since PHP 5 objects are automatically passed by reference.

提交回复
热议问题