8000 [VarDumper] fix dumping objects that implement __debugInfo() · symfony/symfony@6a75bc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a75bc7

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

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

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

Lines changed: 13 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,16 @@ 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+
$a[$k] = $v;
99+
}
100+
}
101+
96102
return $a;
97103
}
98104

0 commit comments

Comments
 (0)
0