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