Skip to content

Commit

Permalink
Dumper: improved dumping of PHP Incomplete Class (also closes #422]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 14, 2020
1 parent 77c3676 commit 1a4d518
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
19 changes: 4 additions & 15 deletions src/Tracy/Dumper/Exposer.php
Expand Up @@ -113,21 +113,10 @@ public static function exposeSplObjectStorage(\SplObjectStorage $obj): array
}


public static function exposePhpIncompleteClass(\__PHP_Incomplete_Class $obj): array
public static function exposePhpIncompleteClass(\__PHP_Incomplete_Class $obj, Value $value, Describer $describer): void
{
$info = ['className' => null, 'private' => [], 'protected' => [], 'public' => []];
foreach ((array) $obj as $name => $value) {
$name = (string) $name;
if ($name === '__PHP_Incomplete_Class_Name') {
$info['className'] = $value;
} elseif (preg_match('#^\x0\*\x0(.+)$#D', $name, $m)) {
$info['protected'][$m[1]] = $value;
} elseif (preg_match('#^\x0(.+)\x0(.+)$#D', $name, $m)) {
$info['private'][$m[1] . '::$' . $m[2]] = $value;
} else {
$info['public'][$name] = $value;
}
}
return $info;
self::exposeObject($obj, $value, $describer);
unset($value->items[0]);
$value->value = ((array) $obj)['__PHP_Incomplete_Class_Name'] . ' (Incomplete Class)';
}
}
20 changes: 8 additions & 12 deletions tests/Tracy/Dumper.objectExporters.phpt
Expand Up @@ -79,18 +79,14 @@ XX
$obj = unserialize('O:1:"Y":7:{s:1:"1";N;s:1:"b";i:2;s:4:"' . "\0" . '*' . "\0" . 'c";N;s:4:"' . "\0" . '*' . "\0" . 'd";s:1:"d";s:4:"' . "\0" . 'Y' . "\0" . 'e";N;s:4:"' . "\0" . 'Y' . "\0" . 'i";s:3:"bar";s:4:"' . "\0" . 'X' . "\0" . 'i";s:3:"foo";}');

Assert::match(<<<'XX'
__PHP_Incomplete_Class #%d%
className: 'Y'
private: array (3)
| 'Y::$e' => null
| 'Y::$i' => 'bar'
| 'X::$i' => 'foo'
protected: array (2)
| 'c' => null
| 'd' => 'd'
public: array (2)
| 1 => null
| 'b' => 2
Y (Incomplete Class) #%d%
1: null
b: 2
c: null
d: 'd'
e: null
i: 'bar'
i: 'foo'
XX
, Dumper::toText($obj));

Expand Down

0 comments on commit 1a4d518

Please sign in to comment.