<?php
$x = "unchecked";
$a = array(1, 2, 3, "is_ref" => &$x);
foreach ($a as $k => $v) {
if ($k !== "is_ref") {
/* CODE FOR TESTING HERE */
// This will cause a copy:
//$a[$k] = null;
//$v += 1;
//$a[$k] = $v;
// This won't:
//var_dump($a);
} else if (isset($x)) {
$x = "was not copied";
unset($x);
$tmp = $a;
$tmp["is_ref"] = "WAS COPIED!!!";
unset($tmp);
echo "######### \$a ".$a["is_ref"]."\n";
}
}
- Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1 - 8.4.2
- ######### $a was not copied
preferences:
96.37 ms | 407 KiB | 5 Q