In PHP, function parameters can be passed by reference, adding an ampersand to the parameter in the function declaration, for example:
function foo(&$bar) {
Now I know that this is not intended to improve performance, but allowing functions to modify variables that usually go out of their scope.
Instead, PHP seems to use Copy On Write to avoid copying objects (or maybe arrays) until they are modified. Thus, for functions that do not change their parameters, the effect should be the same as if you passed them by reference.
However, I was wondering if the "Copy by write" logic can be truncated shortly by link to link and whether this affects performance.
ETA: Of course, I guess this is not faster, and I well know that this is not what links are for. Therefore, I think that my own guesses are not bad, I'm just looking for an answer from someone who really knows what exactly is happening under the hood. Over the five years of PHP development, it has always been difficult for me to get quality information about the internal functions of PHP, apart from the source.
performance pass-by-reference php
Hanno Fietz Oct 07 '08 at 13:04 2008-10-07 13:04
source share