附加到数组而不复制[关闭]

Generally we add to an array with

$myarray[] = $myItem

but if $myItem is a massive object I don't want it to get copied, instead I want it to be assigned by reference. Something like

$myarray[] = &$myItem

but that doesn't work and instead replaces every element in $myarray with $myItem

I tried

$myarray[count($myarray)] = &$myItem

but it still replaces everything in $myarray

I am running PHP v5.5

Objects are always assigned by reference. So:

$collection = array();

$blah = new Blah();

$blah->param = "something";

$collection[] = $blah;

$blah->param = "changed";

echo $collection[0]->param; // will output "changed"

According to How to push a copy of an object into array in PHP

Objects are always passed by reference in php 5 or later.

Therefore this question isn't really a concern anymore.