3v4l.org

run code in 300+ PHP versions simultaneously
<?php $doesNotMatter = ['a' => ['id' => 1], 'b' => ['id' => 2]]; $copy1 = $doesNotMatter; $reference = &$doesNotMatter['a']; $copy2 = $doesNotMatter; // Not a reference! var_dump($doesNotMatter); $copy1['a'] = null; $copy2['b'] = null; var_dump($doesNotMatter); $copy2['a'] = null; $copy2['b'] = null; // Intuitively, this should be a copy of $doesNotMatter and shouldn't affect it at all, but because a // reference exists to $doesNotMatter['a'] when $copy2 is created, that key is copied as a reference. // Basically, when a reference is created, PHP treats both the reference and the original as references, // and this affects object properties and array keys in unintuitive ways. var_dump($doesNotMatter);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { ["a"]=> &array(1) { ["id"]=> int(1) } ["b"]=> array(1) { ["id"]=> int(2) } } array(2) { ["a"]=> &array(1) { ["id"]=> int(1) } ["b"]=> array(1) { ["id"]=> int(2) } } array(2) { ["a"]=> &NULL ["b"]=> array(1) { ["id"]=> int(2) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
131.42 ms | 406 KiB | 5 Q