8000 [VarDumper] fix dumping objects that implement __debugInfo() by nicolas-grekas · Pull Request #32024 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[VarDumper] fix dumping objects that implement __debugInfo() #32024

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[VarDumper] fix dumping objects that implement __debugInfo()
  • Loading branch information
nicolas-grekas committed Jun 13, 2019
commit a9d0038ec0042b39a96c0141e0d8c78a6fa3f362
21 changes: 14 additions & 7 deletions src/Symfony/Component/VarDumper/Caster/Caster.php
Expand Up
Original file line number Diff line number Diff line change
@@ -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