1--TEST-- 2Lazy objects: ReflectionObject::__toString() does not trigger initialization 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 (new ReflectionObject($obj))->__toString(); 18 19 printf("Initialized:\n"); 20 var_dump(!(new ReflectionClass($obj))->isUninitializedLazyObject($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 41Initialized: 42bool(false) 43# Proxy 44Initialized: 45bool(false) 46