1--TEST--
2Lazy objects: Object is still lazy after initializer exception
3--FILE--
4<?php
5
6class C {
7    public $a = 1;
8    public int $b = 2;
9}
10
11function test(string $name, object $obj) {
12    $reflector = new ReflectionClass(C::class);
13
14    printf("# %s:\n", $name);
15
16    try {
17        $reflector->initializeLazyObject($obj);
18    } catch (Exception $e) {
19        printf("%s\n", $e->getMessage());
20    }
21
22    printf("Is lazy: %d\n", $reflector->isUninitializedLazyObject($obj));
23}
24
25$reflector = new ReflectionClass(C::class);
26
27$obj = $reflector->newLazyGhost(function ($obj) {
28    var_dump("initializer");
29    $obj->a = 3;
30    $obj->b = 4;
31    throw new Exception('initializer exception');
32});
33
34test('Ghost', $obj);
35
36$obj = $reflector->newLazyProxy(function ($obj) {
37    var_dump("initializer");
38    $obj->a = 3;
39    $obj->b = 4;
40    throw new Exception('initializer exception');
41});
42
43test('Proxy', $obj);
44
45--EXPECT--
46# Ghost:
47string(11) "initializer"
48initializer exception
49Is lazy: 1
50# Proxy:
51string(11) "initializer"
52initializer exception
53Is lazy: 1
54