1--TEST--
2Lazy objects: resetAsLazy*() on object being initialized
3--FILE--
4<?php
5
6class C {
7    public int $a;
8}
9
10$reflector = new ReflectionClass(C::class);
11
12printf("# Ghost:\n");
13
14$obj = new C();
15$reflector->resetAsLazyGhost($obj, function ($obj) use ($reflector) {
16    try {
17        $reflector->resetAsLazyGhost($obj, function () { });
18    } catch (Error $e) {
19        printf("%s: %s\n", $e::class, $e->getMessage());
20    }
21    try {
22        $reflector->resetAsLazyProxy($obj, function () { });
23    } catch (Error $e) {
24        printf("%s: %s\n", $e::class, $e->getMessage());
25    }
26
27});
28$reflector->initializeLazyObject($obj);
29
30printf("# Proxy:\n");
31
32$obj = new C();
33$reflector->resetAsLazyProxy($obj, function ($obj) use ($reflector) {
34    try {
35        $reflector->resetAsLazyProxy($obj, function () { });
36    } catch (Error $e) {
37        printf("%s: %s\n", $e::class, $e->getMessage());
38    }
39    try {
40        $reflector->resetAsLazyGhost($obj, function () { });
41    } catch (Error $e) {
42        printf("%s: %s\n", $e::class, $e->getMessage());
43    }
44    return new C();
45});
46$reflector->initializeLazyObject($obj);
47
48?>
49==DONE==
50--EXPECT--
51# Ghost:
52Error: Can not reset an object while it is being initialized
53Error: Can not reset an object while it is being initialized
54# Proxy:
55Error: Can not reset an object while it is being initialized
56Error: Can not reset an object while it is being initialized
57==DONE==
58