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