1--TEST--
2Lazy objects: ReflectionClass::initializeLazyObject() on an initialized object is a no-op
3--FILE--
4<?php
5
6class C {
7    public int $a;
8}
9
10function test(string $name, object $obj) {
11    printf("# %s:\n", $name);
12
13    $reflector = new ReflectionClass(C::class);
14
15    var_dump($obj->a);
16
17    var_dump(!$reflector->isUninitializedLazyObject($obj));
18
19    var_dump($reflector?->initializeLazyObject($obj));
20
21    var_dump(!$reflector->isUninitializedLazyObject($obj));
22}
23
24$reflector = new ReflectionClass(C::class);
25
26$obj = $reflector->newLazyGhost(function ($obj) {
27    var_dump("initializer");
28    $obj->a = 1;
29});
30
31test('Ghost', $obj);
32
33$obj = $reflector->newLazyProxy(function ($obj) {
34    var_dump("initializer");
35    $c = new C();
36    $c->a = 1;
37    return $c;
38});
39
40test('Proxy', $obj);
41
42--EXPECTF--
43# Ghost:
44string(11) "initializer"
45int(1)
46bool(true)
47object(C)#%d (1) {
48  ["a"]=>
49  int(1)
50}
51bool(true)
52# Proxy:
53string(11) "initializer"
54int(1)
55bool(true)
56object(C)#%d (1) {
57  ["a"]=>
58  int(1)
59}
60bool(true)
61