1--TEST--
2Lazy objects: resetAsLazy() ignores additional props
3--FILE--
4<?php
5
6class A {
7    public $a;
8}
9
10class B extends A {
11    public $b;
12}
13
14class C extends A {
15    public $a;
16    public $c;
17}
18
19class D extends A {
20    public readonly int $d;
21    public function __construct(bool $init = false) {
22        if ($init) {
23            $this->d = 1;
24        }
25    }
26}
27
28$reflector = new ReflectionClass(A::class);
29
30printf("# B\n");
31
32$obj = new B();
33$obj->a = 1;
34$obj->b = 2;
35$reflector->resetAsLazyGhost($obj, function () {});
36var_dump($obj->b);
37var_dump($obj);
38var_dump($obj->a);
39var_dump($obj);
40
41printf("# C\n");
42
43$obj = new C();
44$obj->a = 1;
45$obj->c = 2;
46$reflector->resetAsLazyGhost($obj, function () {});
47var_dump($obj->c);
48var_dump($obj);
49var_dump($obj->a);
50var_dump($obj);
51
52printf("# D\n");
53
54$obj = new D();
55$obj->a = 1;
56$reflector->resetAsLazyGhost($obj, function ($obj) {
57    $obj->__construct(true);
58});
59var_dump($obj->d ?? 'undef');
60var_dump($obj);
61var_dump($obj->a);
62var_dump($obj);
63
64--EXPECTF--
65# B
66int(2)
67lazy ghost object(B)#%d (1) {
68  ["b"]=>
69  int(2)
70}
71NULL
72object(B)#%d (2) {
73  ["a"]=>
74  NULL
75  ["b"]=>
76  int(2)
77}
78# C
79int(2)
80lazy ghost object(C)#%d (1) {
81  ["c"]=>
82  int(2)
83}
84NULL
85object(C)#%d (2) {
86  ["a"]=>
87  NULL
88  ["c"]=>
89  int(2)
90}
91# D
92string(5) "undef"
93lazy ghost object(D)#%d (0) {
94  ["d"]=>
95  uninitialized(int)
96}
97NULL
98object(D)#%d (2) {
99  ["a"]=>
100  NULL
101  ["d"]=>
102  int(1)
103}
104