Skip to content

Commit faf7b30

Browse files
committed
bug symfony#32024 [VarDumper] fix dumping objects that implement __debugInfo() (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [VarDumper] fix dumping objects that implement __debugInfo() | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Right now it fails if the return value is not an array + it doesn't dump the original details from the object's internals. Commits ------- a9d0038 [VarDumper] fix dumping objects that implement __debugInfo()
2 parents 27316a4 + a9d0038 commit faf7b30

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)