--TEST-- Lazy objects: unset of undefined dynamic property initializes object (2) --FILE-- b = 2; } } function test(string $name, object $obj) { printf("# %s:\n", $name); // no var_dump($obj), so that properties ht is not initialized var_dump('before unset'); unset($obj->a); var_dump($obj); } $reflector = new ReflectionClass(C::class); $obj = $reflector->newLazyGhost(function ($obj) { var_dump("initializer"); $obj->__construct(1); }); test('Ghost', $obj); $obj = $reflector->newLazyProxy(function ($obj) { var_dump("initializer"); return new C(1); }); test('Proxy', $obj); --EXPECTF-- # Ghost: string(12) "before unset" string(11) "initializer" string(14) "C::__construct" object(C)#%d (1) { ["b"]=> int(2) } # Proxy: string(12) "before unset" string(11) "initializer" string(14) "C::__construct" lazy proxy object(C)#%d (1) { ["instance"]=> object(C)#%d (1) { ["b"]=> int(2) } }