1--TEST--
2Lazy objects: Destructor exception in resetAsLazy*()
3--FILE--
4<?php
5
6class C {
7    public readonly int $a;
8
9    public function __construct() {
10        $this->a = 1;
11    }
12
13    public function __destruct() {
14        throw new \Exception(__METHOD__);
15    }
16}
17
18$reflector = new ReflectionClass(C::class);
19
20print "# Ghost:\n";
21
22$obj = new C();
23try {
24    $reflector->resetAsLazyGhost($obj, function ($obj) {
25        var_dump("initializer");
26        $obj->__construct();
27    });
28} catch (\Exception $e) {
29    printf("%s: %s\n", $e::class, $e->getMessage());
30}
31
32// Object was not made lazy
33var_dump(!$reflector->isUninitializedLazyObject($obj));
34
35print "# Proxy:\n";
36
37$obj = new C();
38try {
39    (new ReflectionClass($obj))->resetAsLazyProxy($obj, function ($obj) {
40        var_dump("initializer");
41        return new C();
42    });
43} catch (\Exception $e) {
44    printf("%s: %s\n", $e::class, $e->getMessage());
45}
46
47// Object was not made lazy
48var_dump(!(new ReflectionClass($obj))->isUninitializedLazyObject($obj));
49
50?>
51--EXPECT--
52# Ghost:
53Exception: C::__destruct
54bool(true)
55# Proxy:
56Exception: C::__destruct
57bool(true)
58