bug #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
-------

a9d0038ec0 [VarDumper] fix dumping objects that implement __debugInfo()
This commit is contained in:
Fabien Potencier 2019-06-13 18:26:35 +02:00
commit faf7b305f9

View File

@ -53,13 +53,9 @@ class Caster
$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;
}
@ -93,6 +89,17 @@ class Caster
}
}
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;
}