1--TEST-- 2Lazy objects: serialize initializes object by default 3--FILE-- 4<?php 5 6class C { 7 public int $a; 8 public function __construct() { 9 var_dump(__METHOD__); 10 $this->a = 1; 11 } 12} 13 14function test(string $name, object $obj) { 15 printf("# %s:\n", $name); 16 17 var_dump(serialize($obj)); 18} 19 20$reflector = new ReflectionClass(C::class); 21 22$obj = $reflector->newLazyGhost(function ($obj) { 23 var_dump("initializer"); 24 $obj->__construct(); 25}); 26 27test('Ghost', $obj); 28 29$obj = $reflector->newLazyProxy(function ($obj) { 30 var_dump("initializer"); 31 return new C(); 32}); 33 34test('Proxy', $obj); 35 36--EXPECT-- 37# Ghost: 38string(11) "initializer" 39string(14) "C::__construct" 40string(24) "O:1:"C":1:{s:1:"a";i:1;}" 41# Proxy: 42string(11) "initializer" 43string(14) "C::__construct" 44string(24) "O:1:"C":1:{s:1:"a";i:1;}" 45