1--TEST-- 2Lazy objects: json_encode with dynamic props on initialized object 3--FILE-- 4<?php 5 6#[AllowDynamicProperties] 7class C { 8 public int $a = 1; 9} 10 11$reflector = new ReflectionClass(C::class); 12 13$reflector = new ReflectionClass(C::class); 14 15function test(string $name, object $obj) { 16 printf("# %s\n", $name); 17 18 var_dump(json_decode(json_encode($obj))); 19} 20 21$obj = $reflector->newLazyGhost(function ($obj) { 22 $obj->dyn = 1; 23}); 24 25test('Ghost', $obj); 26 27$obj = $reflector->newLazyProxy(function () { 28 $c = new C(); 29 $c->dyn = 1; 30 return $c; 31}); 32 33test('Proxy', $obj); 34 35--EXPECTF-- 36# Ghost 37object(stdClass)#%d (2) { 38 ["a"]=> 39 int(1) 40 ["dyn"]=> 41 int(1) 42} 43# Proxy 44object(stdClass)#%d (2) { 45 ["a"]=> 46 int(1) 47 ["dyn"]=> 48 int(1) 49} 50