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