1--TEST-- 2Lazy Objects: serialize with __sleep fetches property info from the real instance 3--FILE-- 4<?php 5 6class C { 7 public mixed $a; 8 private mixed $b = 1; 9 function __sleep() { 10 return['a', 'b']; 11 } 12} 13 14$reflector = new ReflectionClass(C::class); 15 16print "Init on serialize and successful initialization\n"; 17 18$obj = $reflector->newLazyProxy(function() { 19 $c = new C; 20 return $c; 21}); 22 23var_dump(serialize($obj)); 24 25print "Init on serialize and failed initialization\n"; 26 27$obj = $reflector->newLazyProxy(function() { 28 throw new \Exception('initializer'); 29}); 30 31try { 32 var_dump(serialize($obj)); 33} catch (Exception $e) { 34 printf("%s: %s\n", $e::class, $e->getMessage()); 35} 36 37?> 38--EXPECTF-- 39Init on serialize and successful initialization 40string(27) "O:1:"C":1:{s:4:"%0C%0b";i:1;}" 41Init on serialize and failed initialization 42Exception: initializer 43