method retrieveObjectVar documentation in bbn\X
Retrieves values from the given object based on the given properties.
Example
$obj = (object)['a' => (object)['e' => 33, 'f' => 'foo'], 'b' => 2, 'c' => 3, 'd' => (object)['g' => 11]];
X::retrieveObjectVar(['a', 'e'], $obj);
// (int) 33
X::retrieveObjectVar(['a', 'f'], $obj);
// (string) foo
X::retrieveObjectVar(['d'], $obj);
// (object) {'g' : 11}
function(array $props, object $obj)
{
$cur = $obj;
foreach ($props as $p) {
if (is_object($cur) && property_exists($cur, $p)) {
$cur = $cur->{$p};
}
else{
throw new Exception("Impossible to find the value in the object");
}
}
return $cur;
}
Retrieves values from the given object based on the given properties. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions