1--TEST--
2Lazy objects: ReflectionClass::initializeLazyObject() error
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    var_dump(!$reflector->isUninitializedLazyObject($obj));
15
16    try {
17        var_dump($reflector?->initializeLazyObject($obj));
18    } catch (Exception $e) {
19        printf("%s\n", $e->getMessage());
20    }
21
22    var_dump(!$reflector->isUninitializedLazyObject($obj));
23}
24
25$reflector = new ReflectionClass(C::class);
26
27$obj = $reflector->newLazyGhost(function ($obj) {
28    var_dump("initializer");
29    throw new \Exception('initializer exception');
30});
31
32test('Ghost', $obj);
33
34$obj = $reflector->newLazyProxy(function ($obj) {
35    var_dump("initializer");
36    throw new \Exception('initializer exception');
37});
38
39test('Proxy', $obj);
40
41--EXPECT--
42# Ghost:
43bool(false)
44string(11) "initializer"
45initializer exception
46bool(false)
47# Proxy:
48bool(false)
49string(11) "initializer"
50initializer exception
51bool(false)
52