Skip to content

Commit a9d0038

Browse files
[VarDumper] fix dumping objects that implement __debugInfo()
1 parent a0b6d3d commit a9d0038

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Symfony/Component/VarDumper/Caster/Caster.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,9 @@ public static function castObject($obj, $class, $hasDebugInfo = false)
5353
$hasDebugInfo = $class->hasMethod('__debugInfo');
5454
$class = $class->name;
5555
}
56-
if ($hasDebugInfo) {
57-
$a = $obj->__debugInfo();
58-
} elseif ($obj instanceof \Closure) {
59-
$a = [];
60-
} else {
61-
$a = (array) $obj;
62-
}
56+
57+
$a = $obj instanceof \Closure ? [] : (array) $obj;
58+
6359
if ($obj instanceof \__PHP_Incomplete_Class) {
6460
return $a;
6561
}
@@ -93,6 +89,17 @@ public static function castObject($obj, $class, $hasDebugInfo = false)
9389
}
9490
}
9591

92+
if ($hasDebugInfo && \is_array($debugInfo = $obj->__debugInfo())) {
93+
foreach ($debugInfo as $k => $v) {
94+
if (!isset($k[0]) || "\0" !== $k[0]) {
95+
$k = self::PREFIX_VIRTUAL.$k;
96+
}
97+
98+
unset($a[$k]);
99+
$a[$k] = $v;
100+
}
101+
}
102+
96103
return $a;
97104
}
98105

0 commit comments

Comments
 (0)