1--TEST-- 2Lazy objects: JIT: ASSIGN_OBJ with dynamic prop 3--FILE-- 4<?php 5 6#[AllowDynamicProperties] 7class C { 8 public int $b = 1; 9 10 public function __construct() { 11 var_dump(__METHOD__); 12 $this->b = 3; 13 } 14} 15 16function test(string $name, object $obj) { 17 printf("# %s:\n", $name); 18 19 var_dump($obj); 20 $obj->a = 2; 21 var_dump($obj); 22} 23 24$reflector = new ReflectionClass(C::class); 25 26$obj = $reflector->newLazyGhost(function ($obj) { 27 var_dump("initializer"); 28 $obj->__construct(); 29}); 30 31test('Ghost', $obj); 32 33$obj = $reflector->newLazyProxy(function ($obj) { 34 var_dump("initializer"); 35 return new C(); 36}); 37 38test('Proxy', $obj); 39 40--EXPECTF-- 41# Ghost: 42lazy ghost object(C)#%d (0) { 43 ["b"]=> 44 uninitialized(int) 45} 46string(11) "initializer" 47string(14) "C::__construct" 48object(C)#%d (2) { 49 ["b"]=> 50 int(3) 51 ["a"]=> 52 int(2) 53} 54# Proxy: 55lazy proxy object(C)#%d (0) { 56 ["b"]=> 57 uninitialized(int) 58} 59string(11) "initializer" 60string(14) "C::__construct" 61lazy proxy object(C)#%d (1) { 62 ["instance"]=> 63 object(C)#%d (2) { 64 ["b"]=> 65 int(3) 66 ["a"]=> 67 int(2) 68 } 69} 70