- print_r: documentation ( source)
- get_object_vars: documentation ( source)
<?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);