1--TEST-- 2Lazy objects: resetAsLazy resets dynamic props 3--FILE-- 4<?php 5 6class Canary { 7 public function __destruct() { 8 var_dump(__METHOD__); 9 } 10} 11 12#[\AllowDynamicProperties] 13class C { 14 public $b; 15 public function __construct() { 16 $this->a = new Canary(); 17 } 18} 19 20$reflector = new ReflectionClass(C::class); 21 22print "# Ghost:\n"; 23 24$obj = new C(); 25$reflector->resetAsLazyGhost($obj, function ($obj) { 26 var_dump("initializer"); 27 $obj->__construct(); 28}); 29 30var_dump($obj); 31var_dump($obj->a); 32var_dump($obj); 33 34print "# Proxy:\n"; 35 36$obj = new C(); 37$reflector->resetAsLazyProxy($obj, function ($obj) { 38 var_dump("initializer"); 39 return new C(); 40}); 41 42var_dump($obj); 43var_dump($obj->a); 44var_dump($obj->a); 45var_dump($obj); 46 47--EXPECTF-- 48# Ghost: 49string(18) "Canary::__destruct" 50lazy ghost object(C)#%d (%d) { 51} 52string(11) "initializer" 53object(Canary)#%d (0) { 54} 55object(C)#%d (2) { 56 ["b"]=> 57 NULL 58 ["a"]=> 59 object(Canary)#%d (0) { 60 } 61} 62# Proxy: 63string(18) "Canary::__destruct" 64string(18) "Canary::__destruct" 65lazy proxy object(C)#%d (%d) { 66} 67string(11) "initializer" 68object(Canary)#%d (0) { 69} 70object(Canary)#%d (0) { 71} 72lazy proxy object(C)#%d (1) { 73 ["instance"]=> 74 object(C)#%d (2) { 75 ["b"]=> 76 NULL 77 ["a"]=> 78 object(Canary)#%d (0) { 79 } 80 } 81} 82string(18) "Canary::__destruct" 83