Skip to content

Commit

Permalink
bug #32024 [VarDumper] fix dumping objects that implement __debugInfo…
Browse files Browse the repository at this point in the history
…() (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()
  • Loading branch information
fabpot committed Jun 13, 2019
2 parents 27316a4 + a9d0038 commit faf7b30
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 faf7b30

Please sign in to comment.