1--TEST-- 2Lazy objects: resetAsLazy*() may call destructors of reset properties 3--FILE-- 4<?php 5 6class Foo { 7 public function __destruct() { 8 printf("%s\n", __METHOD__); 9 } 10} 11 12class Bar { 13 public string $s; 14 public ?Foo $foo; 15 16 public function __destruct() { 17 printf("%s\n", __METHOD__); 18 } 19} 20 21$bar = new Bar(); 22$bar->foo = new Foo(); 23 24$reflector = new ReflectionClass(Bar::class); 25 26print "Reset\n"; 27 28$reflector->resetAsLazyProxy($bar, function (Bar $bar) { 29 $result = new Bar(); 30 $result->foo = null; 31 $result->s = 'init'; 32 return $result; 33}); 34 35print "Dump\n"; 36 37var_dump($bar->s); 38 39print "Done\n"; 40 41?> 42--EXPECT-- 43Reset 44Bar::__destruct 45Foo::__destruct 46Dump 47string(4) "init" 48Done 49Bar::__destruct 50