3 ms·
Then you get the joy of being able to play with it later. $array = array(1,2,3,4,5); foreach ($array as &$value) { echo $value; // some non-mutat
by uxp 14y ago
Then you get the joy of being able to play with it later.
$array = array(1,2,3,4,5);
foreach ($array as &$value) {
echo $value; // some non-mutating action
}
$value = 'woops';
print_r($array); // ([0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => woops)
- jtreminio 14y agoThat's why I tell the developers on my team that if they're thinking of using references in PHP, then they're probably Doing It Wrong.
- smsm42 14y agoUnless they are experienced developers doing complex data structures, this is probably a good advice. References need to be approached very carefully to use them right. It doesn't help that in old PHP versions you had to use references when working with objects, and some people assumed some bad habits from those times and these habits propagate through code without people actually understanding what's going on.