3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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"; } }
based on sWjKB
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
######### $a was not copied