1--TEST-- 2Lazy objects: serialize() with dynamic props on initialized object 3--FILE-- 4<?php 5 6#[AllowDynamicProperties] 7class C { 8 public int $a; 9} 10 11$reflector = new ReflectionClass(C::class); 12 13function test(string $name, object $obj) { 14 printf("# %s\n", $name); 15 16 var_dump(unserialize(serialize($obj))); 17} 18 19$obj = $reflector->newLazyGhost(function ($obj) { 20 $obj->dyn = 1; 21}); 22 23test('Ghost', $obj); 24 25$obj = $reflector->newLazyProxy(function () { 26 $c = new C(); 27 $c->dyn = 1; 28 return $c; 29}); 30 31test('Proxy', $obj); 32 33?> 34--EXPECTF-- 35# Ghost 36object(C)#%d (1) { 37 ["a"]=> 38 uninitialized(int) 39 ["dyn"]=> 40 int(1) 41} 42# Proxy 43object(C)#%d (1) { 44 ["a"]=> 45 uninitialized(int) 46 ["dyn"]=> 47 int(1) 48} 49