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