1--TEST--
2Lazy objects: unset of defined property does not initialize object
3--FILE--
4<?php
5
6#[AllowDynamicProperties]
7class C {
8    public int $a = 1;
9
10    public function __construct(int $a) {
11        var_dump(__METHOD__);
12        $this->a = 2;
13    }
14}
15
16function test(string $name, object $obj) {
17    printf("# %s:\n", $name);
18
19    (new ReflectionProperty($obj, 'a'))->setRawValueWithoutLazyInitialization($obj, 1);
20
21    var_dump($obj);
22    unset($obj->a);
23    var_dump($obj);
24}
25
26$reflector = new ReflectionClass(C::class);
27
28$obj = $reflector->newLazyGhost(function ($obj) {
29    var_dump("initializer");
30    $obj->__construct(1);
31});
32
33test('Ghost', $obj);
34
35$obj = $reflector->newLazyProxy(function ($obj) {
36    var_dump("initializer");
37    return new C(1);
38});
39
40test('Proxy', $obj);
41
42--EXPECTF--
43# Ghost:
44object(C)#%d (1) {
45  ["a"]=>
46  int(1)
47}
48object(C)#%d (0) {
49  ["a"]=>
50  uninitialized(int)
51}
52# Proxy:
53object(C)#%d (1) {
54  ["a"]=>
55  int(1)
56}
57object(C)#%d (0) {
58  ["a"]=>
59  uninitialized(int)
60}
61