1--TEST-- 2Lazy objects: props are initialized to default values before calling initializer 3--FILE-- 4<?php 5 6class C { 7 public $a = 1; 8 public int $b = 2; 9 10 public function __construct() { 11 var_dump(__METHOD__); 12 $this->a = 3; 13 $this->b = 4; 14 } 15} 16 17$reflector = new ReflectionClass(C::class); 18 19$obj = $reflector->newLazyGhost(function ($obj) { 20 var_dump("initializer"); 21 var_dump($obj); 22 $obj->__construct(); 23}); 24 25var_dump($obj); 26var_dump($obj->a); 27var_dump($obj); 28--EXPECTF-- 29lazy ghost object(C)#%d (0) { 30 ["b"]=> 31 uninitialized(int) 32} 33string(11) "initializer" 34object(C)#%d (2) { 35 ["a"]=> 36 int(1) 37 ["b"]=> 38 int(2) 39} 40string(14) "C::__construct" 41int(3) 42object(C)#%d (2) { 43 ["a"]=> 44 int(3) 45 ["b"]=> 46 int(4) 47} 48