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