Loop instead of duplicate code

This commit is contained in:
Tigran Gabrielyan 2013-08-06 15:37:20 -07:00
parent c01aacf72d
commit 84dcd30730

View file

@ -591,24 +591,20 @@ class Debugger {
if (version_compare(PHP_VERSION, '5.3.0') >= 0) { if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
$ref = new ReflectionObject($var); $ref = new ReflectionObject($var);
$reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PROTECTED); $filters = array(
foreach ($reflectionProperties as $reflectionProperty) { ReflectionProperty::IS_PROTECTED => 'protected',
$reflectionProperty->setAccessible(true); ReflectionProperty::IS_PRIVATE => 'private',
$property = $reflectionProperty->getValue($var); );
foreach ($filters as $filter => $visibility) {
$reflectionProperties = $ref->getProperties($filter);
foreach ($reflectionProperties as $reflectionProperty) {
$reflectionProperty->setAccessible(true);
$property = $reflectionProperty->getValue($var);
$value = self::_export($property, $depth - 1, $indent); $value = self::_export($property, $depth - 1, $indent);
$key = $reflectionProperty->name; $key = $reflectionProperty->name;
$props[] = "[protected] $key => " . $value; $props[] = sprintf('[%s] %s => %s', $visibility, $key, $value);
} }
$reflectionProperties = $ref->getProperties(ReflectionProperty::IS_PRIVATE);
foreach ($reflectionProperties as $reflectionProperty) {
$reflectionProperty->setAccessible(true);
$property = $reflectionProperty->getValue($var);
$value = self::_export($property, $depth - 1, $indent);
$key = $reflectionProperty->name;
$props[] = "[private] $key => " . $value;
} }
} }