1--TEST-- 2Lazy objects: serialize does not initializes object if flag is set (properties hashtable) 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 // Builds properties hashtable 18 get_mangled_object_vars($obj); 19 20 $serialized = serialize($obj); 21 $unserialized = unserialize($serialized); 22 var_dump($serialized, $unserialized); 23} 24 25$reflector = new ReflectionClass(C::class); 26 27$obj = $reflector->newLazyGhost(function ($obj) { 28 var_dump("initializer"); 29}, ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE); 30 31test('Ghost', $obj); 32 33$obj = $reflector->newLazyProxy(function ($obj) { 34 var_dump("initializer"); 35}, ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE); 36 37test('Proxy', $obj); 38 39--EXPECTF-- 40# Ghost: 41string(24) "O:1:"C":1:{s:1:"b";i:1;}" 42object(C)#%d (1) { 43 ["a"]=> 44 uninitialized(int) 45 ["b"]=> 46 int(1) 47} 48# Proxy: 49string(24) "O:1:"C":1:{s:1:"b";i:1;}" 50object(C)#%d (1) { 51 ["a"]=> 52 uninitialized(int) 53 ["b"]=> 54 int(1) 55} 56