- var_dump: documentation ( source)
- explode: documentation ( source)
<?php
function getProperty($object, $property) {
$current = $object;
$properties = explode('->', $property);
foreach ($properties as $prop) {
if (is_array($current)) {
$current = $current[$prop];
} else if (is_object($current)) {
$current = $current->$prop;
} else {
break;
}
}
return $current;
}
$a = new stdClass();
$a->foo = new stdClass();
$a->foo->bar = 'baz';
var_dump(getProperty($a, 'foo->bar'));