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