3434use Kint \Value \ArrayValue ;
3535use Kint \Value \ClosedResourceValue ;
3636use Kint \Value \Context \ArrayContext ;
37+ use Kint \Value \Context \BaseContext ;
3738use Kint \Value \Context \ClassDeclaredContext ;
3839use Kint \Value \Context \ClassOwnedContext ;
3940use Kint \Value \Context \ContextInterface ;
4041use Kint \Value \Context \PropertyContext ;
4142use Kint \Value \FixedWidthValue ;
4243use Kint \Value \InstanceValue ;
44+ use Kint \Value \LazyInstanceValue ;
45+ use Kint \Value \ProxyInstanceValue ;
4346use Kint \Value \Representation \ContainerRepresentation ;
4447use Kint \Value \Representation \StringRepresentation ;
4548use Kint \Value \ResourceValue ;
@@ -77,6 +80,7 @@ class Parser
7780 public const TRIGGER_SUCCESS = 1 << 1 ;
7881 public const TRIGGER_RECURSION = 1 << 2 ;
7982 public const TRIGGER_DEPTH_LIMIT = 1 << 3 ;
83+ public const TRIGGER_LAZY = 1 << 4 ;
8084 public const TRIGGER_COMPLETE = self ::TRIGGER_SUCCESS | self ::TRIGGER_RECURSION | self ::TRIGGER_DEPTH_LIMIT ;
8185
8286 /** @psalm-var ?class-string */
@@ -368,7 +372,7 @@ private function getPropsOrderedOld(ReflectionClass $r): array
368372
369373 private function parseObject (object &$ var , ContextInterface $ c ): AbstractValue
370374 {
371- $ hash = \spl_object_hash ($ var );
375+ $ hash = @ \spl_object_hash ($ var );
372376 $ classname = \get_class ($ var );
373377
374378 if (isset ($ this ->object_hashes [$ hash ])) {
@@ -383,26 +387,44 @@ private function parseObject(object &$var, ContextInterface $c): AbstractValue
383387
384388 $ cdepth = $ c ->getDepth ();
385389 $ ap = $ c ->getAccessPath ();
390+ $ robj = new ReflectionObject ($ var );
391+
392+ if (KINT_PHP84 && $ robj ->isUninitializedLazyObject ($ var )) {
393+ // Since getProperties on ReflectionObject also gets dynamic
394+ // properties we have to use a ReflectionClass so as not to
395+ // accidentally initialize lazy objects
396+ $ robj = new ReflectionClass ($ var );
397+ $ object = new LazyInstanceValue ($ c , $ classname , $ hash , \spl_object_id ($ var ));
398+ } elseif (KINT_PHP84 && ($ innerVar = $ robj ->initializeLazyObject ($ var )) !== $ var ) {
399+ $ innerContext = new BaseContext ('instance ' );
400+ $ innerContext ->access_path = $ ap ;
401+ $ innerContext ->depth = $ cdepth + 1 ;
402+ $ inner = $ this ->parse ($ innerVar , $ innerContext );
403+ $ innerContext ->access_path = null ;
404+
405+ return new ProxyInstanceValue ($ c , $ inner , $ classname , $ hash , \spl_object_id ($ var ));
406+ } else {
407+ $ object = new InstanceValue ($ c , $ classname , $ hash , \spl_object_id ($ var ));
408+ }
386409
387410 if ($ this ->depth_limit && $ cdepth >= $ this ->depth_limit ) {
388- $ object = new InstanceValue ($ c , $ classname , $ hash , \spl_object_id ($ var ));
389411 $ object ->flags |= AbstractValue::FLAG_DEPTH_LIMIT ;
390412
391413 return $ this ->applyPluginsComplete ($ var , $ object , self ::TRIGGER_DEPTH_LIMIT );
392414 }
393415
394416 if (KINT_PHP81 ) {
395- $ props = $ this ->getPropsOrdered (new ReflectionObject ( $ var ) );
417+ $ props = $ this ->getPropsOrdered ($ robj );
396418 } else {
397- $ props = $ this ->getPropsOrderedOld (new ReflectionObject ( $ var ) ); // @codeCoverageIgnore
419+ $ props = $ this ->getPropsOrderedOld ($ robj ); // @codeCoverageIgnore
398420 }
399421
400422 $ values = (array ) $ var ;
401423 $ properties = [];
402424
403425 foreach ($ props as $ rprop ) {
404426 if (KINT_PHP81 === false ) {
405- $ rprop ->setAccessible (true );
427+ $ rprop ->setAccessible (true ); // @codeCoverageIgnore
406428 }
407429
408430 $ name = $ rprop ->getName ();
@@ -503,7 +525,6 @@ private function parseObject(object &$var, ContextInterface $c): AbstractValue
503525 }
504526 }
505527
506- $ object = new InstanceValue ($ c , $ classname , $ hash , \spl_object_id ($ var ));
507528 if ($ props ) {
508529 $ object ->setChildren ($ properties );
509530 }
@@ -512,7 +533,11 @@ private function parseObject(object &$var, ContextInterface $c): AbstractValue
512533 $ object ->addRepresentation (new ContainerRepresentation ('Properties ' , $ properties ));
513534 }
514535
515- return $ this ->applyPluginsComplete ($ var , $ object , self ::TRIGGER_SUCCESS );
536+ return $ this ->applyPluginsComplete (
537+ $ var ,
538+ $ object ,
539+ $ object instanceof LazyInstanceValue ? self ::TRIGGER_LAZY : self ::TRIGGER_SUCCESS ,
540+ );
516541 } finally {
517542 unset($ this ->object_hashes [$ hash ]);
518543 }
0 commit comments