- var_dump: documentation ( source)
<?php
$object = new stdClass();
$object->id = 12;
$object->datetime = new \DateTime();
$object->foo = 'foo';
$object->bar = 'foo';
$object->a = 'foo';
$object->b = 'foo';
$object->c = 'foo';
$object->d = 'foo';
$object->e = 'foo';
/* @var callable $toArray */
$toArray = null;
$toArray = function ($object) use (&$toArray) {
$array = [];
foreach ($object as $key => $attribute) {
if (!is_object($attribute) && !is_array($attribute)) {
$array[$key] = $atttribute;
} elseif ($attribute instanceof \DateTime) {
$array[$key] = $attribute->format('c');
} else {
$array[$key] = $toArray($attribute);
}
}
return $array;
};
for ($i = 0; $i < 1000; $i++) {
$toArray($object);
}
var_dump($toArray($object));