0

I've recently discovered that using references in PHP is generally (although not always) a bad idea from a memory management or performance point of view, because of Copy On Write and the way that variables are represented under the hood using zvals.

Can someone offer a fuller explanation? I have seen this link posted a few times on Stack Overflow: http://schlueters.de/blog/archives/125-Do-not-use-PHP-references.html

I also found this reference, which goes into a bit more detail about zvals and how they work. It's in French though, although Google does a pretty good job of translating it: http://julien-pauli.developpez.com/tutoriels/php/internals/variables/

I'm surprised there isn't any more, or better documentation on this, and I wondered if any other Stack Overflow users have come across any clearer or more accessible documentation that I haven't been able to find?

4

1 回答 1

2

Sara Golemon 在http://blog.golemon.com/2007/01/youre-being-lied-to.html上有一篇有趣的文章

这个故事的主旨

当您不需要时通过引用分配值......并不是您智取愚蠢的引擎并获得速度和性能的情况。恰恰相反,是你试图超越引擎而失败了,因为引擎已经做得比你想象的要好。

以及一般 zvals 的一些背景知识。但是这两个都有点老了。不知道这些年来发生了多少变化。

于 2014-02-23T23:05:26.890 回答