3v4l.org

run code in 300+ PHP versions simultaneously
<?php class obj implements \ArrayAccess , \IteratorAggregate { public function __construct() { foreach(array("one" => 1, "two" => 2, "three" => 3) as $offset => $value) $this->{$offset} = $value; } public function offsetSet($offset, $value) { $this->{$offset} = $value; } public function offsetExists($offset) { return isset($this->{$offset}); } public function offsetUnset($offset) { unset($this->{$offset}); } public function offsetGet($offset) { return isset($this->{$offset}) ? $this->{$offset} : null; } function getIterator() { return new \ArrayIterator($this); } } $obj = new obj; foreach($obj as $offset => $value) unset($obj[$offset]); print_r($obj); foreach(get_object_vars($obj) as $offset => $value) unset($obj[$offset]); print_r($obj);

preferences:
45.87 ms | 402 KiB | 5 Q