1--TEST--
2Lazy objects: unset of magic property may not initialize object if method does not observe object state
3--FILE--
4<?php
5
6class C {
7    public int $b = 1;
8
9    public function __construct(int $a) {
10        var_dump(__METHOD__);
11        $this->b = 2;
12    }
13
14    public function __unset($name) {
15    }
16}
17
18function test(string $name, object $obj) {
19    printf("# %s:\n", $name);
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:
44lazy ghost object(C)#%d (0) {
45  ["b"]=>
46  uninitialized(int)
47}
48lazy ghost object(C)#%d (0) {
49  ["b"]=>
50  uninitialized(int)
51}
52# Proxy:
53lazy proxy object(C)#%d (0) {
54  ["b"]=>
55  uninitialized(int)
56}
57lazy proxy object(C)#%d (0) {
58  ["b"]=>
59  uninitialized(int)
60}
61