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