Skip to content

Commit 16daacd

Browse files
committed
Dumper: added support for uninitialized lazy objects
1 parent f7de59e commit 16daacd

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Tracy/Dumper/Exposer.php

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ 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+
//$describer->addPropertyTo($value, 'lazy-object', '', Value::PropertyVirtual);
25+
$value->value .= ' (lazy)';
26+
if ($init = $rc->getLazyInitializer($obj)) {
27+
$describer->addPropertyTo($value, 'initializer', $init, Value::PropertyVirtual);
28+
}
29+
return;
30+
}
31+
2332
$values = get_mangled_object_vars($obj);
2433
$props = self::getProperties($obj::class);
2534

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
);
33+

0 commit comments

Comments
 (0)