3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // works correctly $hash = (object) [ 'a' => 1, 'b' => 2, 'c' => 3, ]; foreach ($hash as $key => $value) { var_dump($key); unset($hash->$key); } echo "\n"; // BUG: skips item 'b' $hash = (object) [ 'a' => 1, 'b' => 2, 'c' => 3, ]; $it = new ArrayIterator($hash); foreach ($it as $key => $value) { var_dump($key); unset($hash->$key); }
Output for 7.0.0 - 7.3.0beta1
string(1) "a" string(1) "b" string(1) "c" string(1) "a" string(1) "c"
Output for 5.5.0 - 5.6.28
string(1) "a" string(1) "b" string(1) "c" string(1) "a" string(1) "b" string(1) "c"