1--TEST-- 2Lazy objects: serialize during hook initializes object by default 3--FILE-- 4<?php 5 6class C { 7 public $a { 8 get { return serialize($this); } 9 set ($value) { $this->a = $value; } 10 } 11 public function __construct() { 12 var_dump(__METHOD__); 13 $this->a = 1; 14 } 15} 16 17function test(string $name, object $obj) { 18 printf("# %s:\n", $name); 19 20 var_dump($obj->a); 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