1--TEST-- 2Lazy objects: serialize does not initializes object if flag is set 3--FILE-- 4<?php 5 6class C { 7 public int $a; 8 public int $b; 9} 10 11 12function test(string $name, object $obj) { 13 printf("# %s:\n", $name); 14 15 (new ReflectionProperty($obj, 'b'))->setRawValueWithoutLazyInitialization($obj, 1); 16 17 $serialized = serialize($obj); 18 $unserialized = unserialize($serialized); 19 var_dump($serialized, $unserialized); 20} 21 22$reflector = new ReflectionClass(C::class); 23 24$obj = $reflector->newLazyGhost(function ($obj) { 25 var_dump("initializer"); 26}, ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE); 27 28test('Ghost', $obj); 29 30$obj = $reflector->newLazyProxy(function ($obj) { 31 var_dump("initializer"); 32}, ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE); 33 34test('Proxy', $obj); 35 36--EXPECTF-- 37# Ghost: 38string(24) "O:1:"C":1:{s:1:"b";i:1;}" 39object(C)#%d (1) { 40 ["a"]=> 41 uninitialized(int) 42 ["b"]=> 43 int(1) 44} 45# Proxy: 46string(24) "O:1:"C":1:{s:1:"b";i:1;}" 47object(C)#%d (1) { 48 ["a"]=> 49 uninitialized(int) 50 ["b"]=> 51 int(1) 52} 53