From 30a91f0a5f4ede8620bfd1479d491d982f92da53 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 25 Nov 2024 12:17:42 +0100 Subject: [PATCH] Dumper: added support for uninitialized lazy objects --- src/Tracy/Dumper/Exposer.php | 9 +++++ .../Tracy/Dumper.toText().specials.lazy.phpt | 33 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 tests/Tracy/Dumper.toText().specials.lazy.phpt diff --git a/src/Tracy/Dumper/Exposer.php b/src/Tracy/Dumper/Exposer.php index eb14a504a..28e3f55f8 100644 --- a/src/Tracy/Dumper/Exposer.php +++ b/src/Tracy/Dumper/Exposer.php @@ -20,6 +20,15 @@ final class Exposer { public static function exposeObject(object $obj, Value $value, Describer $describer): void { + if (PHP_VERSION_ID >= 80400 && ($rc = new \ReflectionClass($obj))->isUninitializedLazyObject($obj)) { + //$describer->addPropertyTo($value, 'lazy-object', '', Value::PropertyVirtual); + $value->value .= ' (lazy)'; + if ($init = $rc->getLazyInitializer($obj)) { + $describer->addPropertyTo($value, 'initializer', $init, Value::PropertyVirtual); + } + return; + } + $values = get_mangled_object_vars($obj); $props = self::getProperties($obj::class); diff --git a/tests/Tracy/Dumper.toText().specials.lazy.phpt b/tests/Tracy/Dumper.toText().specials.lazy.phpt new file mode 100644 index 000000000..b78774b5c --- /dev/null +++ b/tests/Tracy/Dumper.toText().specials.lazy.phpt @@ -0,0 +1,33 @@ +newLazyGhost(function (MyClass $ghost) {}); + + +Assert::match( + <<<'XX' + array (1) + 0 => MyClass (lazy) #%d% + | initializer: Closure($ghost) #%d% + XX, + Dumper::toText([$ghost], [Dumper::DEPTH => 3]), +); +