1--TEST-- 2Lazy objects: serialize initializes object by default (properties hashtable) 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 // Builds properties hashtable 18 get_object_vars($obj); 19 20 var_dump(serialize($obj)); 21} 22 23$reflector = new ReflectionClass(C::class); 24 25$obj = $reflector->newLazyGhost(function ($obj) { 26 var_dump("initializer"); 27 $obj->__construct(); 28}); 29 30test('Ghost', $obj); 31 32$obj = $reflector->newLazyProxy(function ($obj) { 33 var_dump("initializer"); 34 return new C(); 35}); 36 37test('Proxy', $obj); 38 39--EXPECT-- 40# Ghost: 41string(11) "initializer" 42string(14) "C::__construct" 43string(24) "O:1:"C":1:{s:1:"a";i:1;}" 44# Proxy: 45string(11) "initializer" 46string(14) "C::__construct" 47string(24) "O:1:"C":1:{s:1:"a";i:1;}" 48