For the record (php 7.0 - win32)
I am testing it (i passed a variable to a function then i changed the value inside the function) and i found:
a) unset($var) and $var=null act equally.
b) passing an array by reference versus by value, doubles the memory usage at some point. Why?, i don't know. I found it with memory_get_peak_usage(). However, memory_get_usage() will not change so i guess that its duplicates the information (may be in a temporal variable) then it discards.
For example: (the memory is just an approximation)
$var= (10mb of data as an array) = memory peak 10mb.
function functionval($var) {
$var= (100mb of data) = memory peak 110mb.
}
function functionref(&$var) {
$var= (100mb of data) = memory peak 210mb. !!!
}
but
$var= (100mb of data as an array) = memory peak 100mb.
function functionval($var) {
$var= (10mb of data) = memory peak 110mb.
}
function functionref(&$var) {
$var= (10mb of data) = memory peak 120mb. !!!
}
and
$var= (100mb of data as an array) = memory peak 100mb.
function functionval($var) {
$var= (100mb of data) = memory peak 200mb.
}
function functionref(&$var) {
$var= (100mb of data) = memory peak 300mb. !!! <-- why???
}
also
$var= (100mb of data as an array) = memory peak 100mb.
function functionval($var) {
not changing the data. = memory peak 100mb.
}
function functionref(&$var) {
not changing the data. = memory peak 100mb.
}
c) passing parameters as value or reference will practically not change the execution time.
d) passing objects as reference, doubles the memory usage at some point.