1--TEST-- 2Lazy objects: get_object_vars initializes object 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 14$reflector = new ReflectionClass(C::class); 15 16print "# Ghost:\n"; 17 18$obj = $reflector->newLazyGhost(function ($obj) { 19 var_dump("initializer"); 20 $obj->__construct(); 21}); 22 23var_dump(get_object_vars($obj)); 24 25$obj->a = 2; 26var_dump(get_object_vars($obj)); 27 28print "# Proxy:\n"; 29 30$obj = $reflector->newLazyProxy(function ($obj) { 31 var_dump("initializer"); 32 return new C(); 33}); 34 35var_dump(get_object_vars($obj)); 36 37$obj->a = 2; 38var_dump(get_object_vars($obj)); 39 40--EXPECT-- 41# Ghost: 42string(11) "initializer" 43string(14) "C::__construct" 44array(1) { 45 ["a"]=> 46 int(1) 47} 48array(1) { 49 ["a"]=> 50 int(2) 51} 52# Proxy: 53string(11) "initializer" 54string(14) "C::__construct" 55array(1) { 56 ["a"]=> 57 int(1) 58} 59array(1) { 60 ["a"]=> 61 int(2) 62} 63