3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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'));
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
string(3) "baz"