1--TEST-- 2Lazy objects: skipLazyInitialization() may realize object if last lazy prop 3--FILE-- 4<?php 5 6class C { 7 public $a = 1; 8 public $b; 9} 10 11function test(string $name, object $obj) { 12 printf("# %s\n", $name); 13 14 $reflector = new ReflectionClass(C::class); 15 $reflector->getProperty('a')->skipLazyInitialization($obj); 16 $reflector->getProperty('b')->skipLazyInitialization($obj); 17 18 var_dump(!$reflector->isUninitializedLazyObject($obj)); 19 var_dump($obj); 20} 21 22$reflector = new ReflectionClass(C::class); 23$obj = $reflector->newLazyGhost(function () { 24 throw new \Exception('initializer'); 25}); 26 27test('Ghost', $obj); 28 29$obj = $reflector->newLazyProxy(function () { 30 throw new \Exception('initializer'); 31}); 32 33test('Proxy', $obj); 34 35?> 36--EXPECTF-- 37# Ghost 38bool(true) 39object(C)#%d (2) { 40 ["a"]=> 41 int(1) 42 ["b"]=> 43 NULL 44} 45# Proxy 46bool(true) 47object(C)#%d (2) { 48 ["a"]=> 49 int(1) 50 ["b"]=> 51 NULL 52} 53