1--TEST-- 2Lazy objects: var_dump may initialize object with __debugInfo() method 3--FILE-- 4<?php 5 6class C { 7 public int $a; 8 public function __construct() { 9 var_dump(__METHOD__); 10 $this->a = 1; 11 } 12 public function __debugInfo() { 13 return [$this->a]; 14 } 15} 16 17function test(string $name, object $obj) { 18 $reflector = new ReflectionClass(C::class); 19 printf("# %s\n", $name); 20 21 var_dump($obj); 22 printf("Initialized:\n"); 23 var_dump(!$reflector->isUninitializedLazyObject($obj)); 24} 25 26$reflector = new ReflectionClass(C::class); 27 28$obj = $reflector->newLazyGhost(function ($obj) { 29 var_dump("initializer"); 30 $obj->__construct(); 31}); 32 33test('Ghost', $obj); 34 35$obj = $reflector->newLazyProxy(function ($obj) { 36 var_dump("initializer"); 37 return new C(); 38}); 39 40test('Proxy', $obj); 41 42--EXPECTF-- 43# Ghost 44string(11) "initializer" 45string(14) "C::__construct" 46object(C)#%d (1) { 47 [0]=> 48 int(1) 49} 50Initialized: 51bool(true) 52# Proxy 53string(11) "initializer" 54string(14) "C::__construct" 55lazy proxy object(C)#%d (1) { 56 [0]=> 57 int(1) 58} 59Initialized: 60bool(true) 61