Skip to content

Commit 7253e83

Browse files
committed
Dumper: added support for uninitialized lazy objects
1 parent bb1eedb commit 7253e83

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Tracy/Dumper/Exposer.php

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ final class Exposer
2020
{
2121
public static function exposeObject(object $obj, Value $value, Describer $describer): void
2222
{
23+
if (PHP_VERSION_ID >= 80400 && ($rc = new \ReflectionClass($obj))->isUninitializedLazyObject($obj)) {
24+
$value->value .= ' (lazy)';
25+
if ($init = $rc->getLazyInitializer($obj)) {
26+
$describer->addPropertyTo($value, 'initializer', $init, Value::PropertyVirtual);
27+
}
28+
return;
29+
}
30+
2331
$values = get_mangled_object_vars($obj);
2432
$props = self::getProperties($obj::class);
2533

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Test: Tracy\Dumper::toText() & lazy object
5+
* @phpversion 8.4
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
use Tester\Assert;
11+
use Tracy\Dumper;
12+
13+
require __DIR__ . '/../bootstrap.php';
14+
15+
16+
class MyClass
17+
{
18+
public $foo;
19+
}
20+
21+
$rc = new ReflectionClass(MyClass::class);
22+
$ghost = $rc->newLazyGhost(function (MyClass $ghost) {});
23+
24+
25+
Assert::match(
26+
<<<'XX'
27+
array (1)
28+
0 => MyClass (lazy) #%d%
29+
| initializer: Closure($ghost) #%d%
30+
XX,
31+
Dumper::toText([$ghost], [Dumper::DEPTH => 3]),
32+
);

0 commit comments

Comments
 (0)