1--TEST-- 2Lazy objects: properties with no default values are left uninitialized 3--FILE-- 4<?php 5 6class C { 7 public $a; 8 public int $b; 9 10 public function __construct() { 11 var_dump(__METHOD__); 12 } 13} 14 15$reflector = new ReflectionClass(C::class); 16 17$obj = $reflector->newLazyGhost(function ($obj) { 18 var_dump("initializer"); 19 $obj->__construct(); 20}); 21 22var_dump($obj); 23var_dump($obj->a); 24try { 25 var_dump($obj->b); 26} catch (Error $e) { 27 printf("%s\n", $e); 28} 29var_dump($obj); 30--EXPECTF-- 31lazy ghost object(C)#%d (0) { 32 ["b"]=> 33 uninitialized(int) 34} 35string(11) "initializer" 36string(14) "C::__construct" 37NULL 38Error: Typed property C::$b must not be accessed before initialization in %s:%d 39Stack trace: 40#0 {main} 41object(C)#%d (1) { 42 ["a"]=> 43 NULL 44 ["b"]=> 45 uninitialized(int) 46} 47