1--TEST-- 2Lazy objects: serialize() a lazy object that previously failed to initialize 3--FILE-- 4<?php 5 6#[AllowDynamicProperties] 7class C { 8 public int $a; 9 public $b; 10} 11 12$reflector = new ReflectionClass(C::class); 13 14function test(string $name, object $obj) { 15 printf("# %s\n", $name); 16 17 $reflector = new ReflectionClass(C::class); 18 try { 19 $reflector->initializeLazyObject($obj); 20 } catch (Exception $e) { 21 printf("%s: %s\n", $e::class, $e->getMessage()); 22 } 23 24 try { 25 var_dump(unserialize(serialize($obj))); 26 } catch (Exception $e) { 27 printf("%s: %s\n", $e::class, $e->getMessage()); 28 } 29} 30 31$obj = $reflector->newLazyGhost(function ($obj) { 32 throw new \Exception('Initializer'); 33}); 34 35test('Ghost', $obj); 36 37$obj = $reflector->newLazyProxy(function () { 38 throw new \Exception('Initializer'); 39}); 40 41test('Proxy', $obj); 42 43?> 44--EXPECT-- 45# Ghost 46Exception: Initializer 47Exception: Initializer 48# Proxy 49Exception: Initializer 50Exception: Initializer 51