This is interesting.
<?php
define ('ITEMS', 1000);
define ('REPEAT', 10000);
// A function which does nothing
function foo($array) {}
// A largish array
$array = array_fill(0, ITEMS, 'whatever');
// An unused reference to the array
$reference = &$array;
// Start timer
$start = microtime(true);
// Call function which does nothing, pass array as param
for ($i=0; $i < REPEAT; $i++) {
foo($array);
}
// End timer
$duration = microtime(true) - $start;
$duration = number_format($duration, 4);
echo "Duration: {$duration}s\n";
Running this code (on a reasonably fast server, PHP 5.5) yields:
Duration: 0.5552s
However, if you comment out the line which assigns the (unused) refence:
// $reference = &$array;
Things get much faster:
Duration: 0.0022s
But if you add reference to function parametar:
Is it possible new variable in function parameter caries reference duplication and eat's memory!?