As my understanding , when i passed array by value , a copy of array is created.
i.e in below program $y & $z should need same memory as of $x. however memory utilization hardly increases.
Obviousy my understanding is wrong , Can anyone explain the reason.
for($i=0;$i<1000000;$i++)
$x[] = $i; // memory usage : 76519792
echo memory_get_usage();
function abc($y){
$y[1] = 1; //memory usage : 76519948
$z[]= $y; //memory usage : 76520308
}
I heard that php uses copy-on-write:
http://en.wikipedia.org/wiki/Copy-on-write
as an example:
and similar behaviour with the function calls:
PS: I am testing this on windows, maybe it is different on linux