3v4l.org

run code in 300+ PHP versions simultaneously
<?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); }

preferences:
73.31 ms | 402 KiB | 5 Q