1--TEST--
2Lazy objects: property write to dynamic property initializes object
3--FILE--
4<?php
5
6#[AllowDynamicProperties]
7class C {
8    public $a;
9    public int $b = 1;
10
11    public function __construct() {
12        var_dump(__METHOD__);
13        $this->a = 1;
14        $this->b = 2;
15    }
16}
17function test(string $name, object $obj) {
18    printf("# %s:\n", $name);
19
20    var_dump($obj);
21    $obj->custom = 3;
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();
30});
31
32test('Ghost', $obj);
33
34$obj = $reflector->newLazyProxy(function ($obj) {
35    var_dump("initializer");
36    return new C();
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 (3) {
50  ["a"]=>
51  int(1)
52  ["b"]=>
53  int(2)
54  ["custom"]=>
55  int(3)
56}
57# Proxy:
58lazy proxy object(C)#%d (0) {
59  ["b"]=>
60  uninitialized(int)
61}
62string(11) "initializer"
63string(14) "C::__construct"
64lazy proxy object(C)#%d (1) {
65  ["instance"]=>
66  object(C)#%d (3) {
67    ["a"]=>
68    int(1)
69    ["b"]=>
70    int(2)
71    ["custom"]=>
72    int(3)
73  }
74}
75