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