PHP Performance : Copy vs. Reference

后端 未结 6 1444
南旧
南旧 2021-01-18 02:26

Hey there. Today I wrote a small benchmark script to compare performance of copying variables vs. creating references to them. I was expecting, that creating references to l

6条回答
  •  执念已碎
    2021-01-18 03:00

    Generally speaking in PHP, calling by reference is not something you'd do for performance reasons; it's something you'd do for functional reasons - ie because you actually want the referenced variable to be updated.

    If you don't have a functional reason for calling by reference then you should stick with regular parameter passing, because PHP handles things perfectly efficiently that way.

    (that said, as others have pointed out, your example code isn't exactly doing what you think it is anyway ;))

提交回复
热议问题