Skip to content

Commit

Permalink
Exposer: includes uninitialized properties [Closes #448] WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 29, 2020
1 parent 9389310 commit 0307285
Showing 1 changed file with 30 additions and 15 deletions.
45 changes: 30 additions & 15 deletions src/Tracy/Dumper/Exposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,38 @@ final class Exposer
{
public static function exposeObject(object $obj, Value $value, Describer $describer): void
{
$defaults = get_class_vars(get_class($obj));
$arr = (array) $obj;
$tmp = $arr; // bug #79477, PHP < 7.4.6
foreach ($tmp as $k => $v) {
$refId = $describer->getReferenceId($tmp, $k);
$type = Value::PROP_PUBLIC;
if (isset($k[0]) && $k[0] === "\x00") {
$info = explode("\00", $k);
$k = end($info);
$type = $info[1] === '*' ? Value::PROP_PROTECTED : $info[1];
$values = (array) $obj;
$tmp = $values; // bug #79477, PHP < 7.4.6
$class = get_class($obj);
$rc = new \ReflectionObject($obj);

foreach ($rc->getProperties() as $prop) {
$k = $name = $prop->getName();

if ($prop->isDefault()) {
$type = Value::PROP_PUBLIC;
if ($prop->isPrivate()) {
$type = $class;
$k = "\x00$class\x00$k"; // TODO
} elseif ($prop->isProtected()) {
$type = Value::PROP_PROTECTED;
$k = "\x00*\x00$k";
}
if (!array_key_exists($k, $values)) {
$value->items[] = [$name, new Value(Value::TYPE_TEXT, 'undefined'), $type];
continue;
}
} else {
$type = array_key_exists($k, $defaults)
? Value::PROP_PUBLIC
: Value::PROP_DYNAMIC;
$k = (string) $k;
$type = Value::PROP_DYNAMIC;
}
$describer->addPropertyTo($value, $k, $v, $type, $refId);

$describer->addPropertyTo(
$value,
$name,
$values[$k],
$type,
$describer->getReferenceId($tmp, $k)
);
}
}

Expand Down

0 comments on commit 0307285

Please sign in to comment.