1--TEST-- 2Lazy objects: resetAsLazy deletes reference source type 3--FILE-- 4<?php 5 6class C { 7 public int $a; 8 9 public function __construct() { 10 $this->a = 1; 11 } 12} 13 14$reflector = new ReflectionClass(C::class); 15 16print "# Ghost:\n"; 17 18$obj = new C(); 19$ref = &$obj->a; 20try { 21 $ref = 'string'; 22} catch (\Error $e) { 23 printf("%s: %s\n", $e::class, $e->getMessage()); 24} 25$reflector->resetAsLazyGhost($obj, function ($obj) { 26 var_dump("initializer"); 27 $obj->__construct(); 28}); 29 30$ref = 'string'; 31var_dump($obj); 32var_dump($obj->a); 33var_dump($obj); 34 35print "# Proxy:\n"; 36 37$obj = new C(); 38$ref = &$obj->a; 39try { 40 $ref = 'string'; 41} catch (\Error $e) { 42 printf("%s: %s\n", $e::class, $e->getMessage()); 43} 44$reflector->resetAsLazyProxy($obj, function ($obj) { 45 var_dump("initializer"); 46 return new C(); 47}); 48 49$ret = 'string'; 50var_dump($obj); 51var_dump($obj->a); 52var_dump($obj->a); 53var_dump($obj); 54 55--EXPECTF-- 56# Ghost: 57TypeError: Cannot assign string to reference held by property C::$a of type int 58lazy ghost object(C)#%d (0) { 59 ["a"]=> 60 uninitialized(int) 61} 62string(11) "initializer" 63int(1) 64object(C)#%d (1) { 65 ["a"]=> 66 int(1) 67} 68# Proxy: 69TypeError: Cannot assign string to reference held by property C::$a of type int 70lazy proxy object(C)#%d (0) { 71 ["a"]=> 72 uninitialized(int) 73} 74string(11) "initializer" 75int(1) 76int(1) 77lazy proxy object(C)#%d (1) { 78 ["instance"]=> 79 object(C)#%d (1) { 80 ["a"]=> 81 int(1) 82 } 83} 84