1--TEST--
2Lazy objects: markLazyObjectAsInitialized() initializes properties to their default value and skips initializer
3--FILE--
4<?php
5
6class C {
7    public int $a = 1;
8}
9
10function test(string $name, object $obj) {
11    printf("# %s:\n", $name);
12
13    $reflector = new ReflectionClass(C::class);
14
15    printf("Initialized:\n");
16    var_dump(!$reflector->isUninitializedLazyObject($obj));
17
18    printf("markLazyObjectAsInitialized(true) returns \$obj:\n");
19    var_dump($reflector?->markLazyObjectAsInitialized($obj) === $obj);
20
21    printf("Initialized:\n");
22    var_dump(!$reflector->isUninitializedLazyObject($obj));
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->a = 1;
31});
32
33test('Ghost', $obj);
34
35$obj = $reflector->newLazyProxy(function ($obj) {
36    var_dump("initializer");
37    $c = new C();
38    $c->a = 1;
39    return $c;
40});
41
42test('Proxy', $obj);
43
44--EXPECTF--
45# Ghost:
46Initialized:
47bool(false)
48markLazyObjectAsInitialized(true) returns $obj:
49bool(true)
50Initialized:
51bool(true)
52object(C)#%d (1) {
53  ["a"]=>
54  int(1)
55}
56# Proxy:
57Initialized:
58bool(false)
59markLazyObjectAsInitialized(true) returns $obj:
60bool(true)
61Initialized:
62bool(true)
63object(C)#%d (1) {
64  ["a"]=>
65  int(1)
66}
67