Skip to content

Commit

Permalink
[VarDumper] fix dumping objects that implement __debugInfo()
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 13, 2019
1 parent a0b6d3d commit a9d0038
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Symfony/Component/VarDumper/Caster/Caster.php
Expand Up @@ -53,13 +53,9 @@ public static function castObject($obj, $class, $hasDebugInfo = false)
$hasDebugInfo = $class->hasMethod('__debugInfo');
$class = $class->name;
}
if ($hasDebugInfo) {
$a = $obj->__debugInfo();
} elseif ($obj instanceof \Closure) {
$a = [];
} else {
$a = (array) $obj;
}

$a = $obj instanceof \Closure ? [] : (array) $obj;

if ($obj instanceof \__PHP_Incomplete_Class) {
return $a;
}
Expand Down Expand Up @@ -93,6 +89,17 @@ public static function castObject($obj, $class, $hasDebugInfo = false)
}
}

if ($hasDebugInfo && \is_array($debugInfo = $obj->__debugInfo())) {
foreach ($debugInfo as $k => $v) {
if (!isset($k[0]) || "\0" !== $k[0]) {
$k = self::PREFIX_VIRTUAL.$k;
}

unset($a[$k]);
$a[$k] = $v;
}
}

return $a;
}

Expand Down

0 comments on commit a9d0038

Please sign in to comment.