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