Skip to content

Commit

Permalink
Dumper: added support for uninitialized lazy objects
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 25, 2024
1 parent 017d6bf commit 17fdd9e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Tracy/Dumper/Exposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ 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);
$value->items[0][1]->collapsed = false;
}
return;
}

$values = get_mangled_object_vars($obj);
$props = self::getProperties($obj::class);

Expand Down
33 changes: 33 additions & 0 deletions tests/Tracy/Dumper.toText().specials.lazy.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* Test: Tracy\Dumper::toText() & lazy object
* @phpversion 8.4
*/

declare(strict_types=1);

use Tester\Assert;
use Tracy\Dumper;

require __DIR__ . '/../bootstrap.php';


class MyClass
{
public $foo;
}

$rc = new ReflectionClass(MyClass::class);
$ghost = $rc->newLazyGhost(function (MyClass $ghost) {});


Assert::match(
<<<'XX'
array (1)
0 => MyClass (lazy) #%d%
| initializer: Closure($ghost) #%d%
XX,
Dumper::toText([$ghost], [Dumper::DEPTH => 3]),
);

0 comments on commit 17fdd9e

Please sign in to comment.