1--TEST-- 2Lazy objects: dynamic property op initializes object 3--FILE-- 4<?php 5 6#[AllowDynamicProperties] 7class C { 8 public int $a = 1; 9 public function __construct() { 10 var_dump(__METHOD__); 11 } 12} 13 14function test(string $name, object $obj) { 15 printf("# %s:\n", $name); 16 17 var_dump($obj); 18 var_dump(@$obj->dynamic++); 19 var_dump($obj); 20} 21 22$reflector = new ReflectionClass(C::class); 23 24$obj = $reflector->newLazyGhost(function ($obj) { 25 var_dump("initializer"); 26 $obj->__construct(); 27}); 28 29test('Ghost', $obj); 30 31$obj = $reflector->newLazyProxy(function ($obj) { 32 var_dump("initializer"); 33 return new C(); 34}); 35 36test('Proxy', $obj); 37 38--EXPECTF-- 39# Ghost: 40lazy ghost object(C)#%d (0) { 41 ["a"]=> 42 uninitialized(int) 43} 44string(11) "initializer" 45string(14) "C::__construct" 46NULL 47object(C)#%d (2) { 48 ["a"]=> 49 int(1) 50 ["dynamic"]=> 51 int(1) 52} 53# Proxy: 54lazy proxy object(C)#%d (0) { 55 ["a"]=> 56 uninitialized(int) 57} 58string(11) "initializer" 59string(14) "C::__construct" 60NULL 61lazy proxy object(C)#%d (1) { 62 ["instance"]=> 63 object(C)#%d (2) { 64 ["a"]=> 65 int(1) 66 ["dynamic"]=> 67 int(1) 68 } 69} 70