1--TEST-- 2Lazy objects: Initializer effects are reverted after exception (nested) 3--FILE-- 4<?php 5 6class A { 7 public $a; 8} 9class B { 10 public $b; 11} 12class C { 13 public $c; 14} 15 16$aReflector = new ReflectionClass(A::class); 17$bReflector = new ReflectionClass(B::class); 18$cReflector = new ReflectionClass(C::class); 19 20$c = $cReflector->newLazyGhost(function ($c) { 21 $c->c = 1; 22}); 23 24$b = $bReflector->newLazyGhost(function () { 25 throw new \Exception('xxx'); 26}); 27 28$a = $aReflector->newLazyGhost(function ($a) use ($b, $c) { 29 $a->a = $c->c + $b->b; 30}); 31 32try { 33 $a->init = 'please'; 34} catch (\Exception $e) { 35 printf("%s: %s\n", $e::class, $e->getMessage()); 36} 37 38var_dump($a, $b, $c); 39 40?> 41--EXPECTF-- 42Exception: xxx 43lazy ghost object(A)#%d (0) { 44} 45lazy ghost object(B)#%d (0) { 46} 47object(C)#%d (1) { 48 ["c"]=> 49 int(1) 50} 51