Skip to content

Instantly share code, notes, and snippets.

@bartfeenstra
Created November 15, 2015 16:18
Show Gist options
  • Save bartfeenstra/e0eb807f3e9ec4fb49ec to your computer and use it in GitHub Desktop.
Save bartfeenstra/e0eb807f3e9ec4fb49ec to your computer and use it in GitHub Desktop.
protected function inspect($data, array $path = []) {
// Depth protection.
if (count($path) > 9) {
return;
}
// Make sure the data is either a scalar or an array.
if (is_object($data)) {
if (strpos(get_class($data), 'Connection') !== FALSE) {
var_dump(get_class($data));
print_r($path);
}
$reflector = new \ReflectionObject($data);
$property_values = [];
foreach ($reflector->getProperties() as $property) {
if ($property->isStatic()) {
continue;
}
$property->setAccessible(TRUE);
$property_values[$property->getName()] = $property->getValue($data);
}
$data = $property_values;
}
if (is_array($data)) {
foreach ($data as $key => $value) {
$this->inspect($value, array_merge($path, [$key]));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment