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