1--TEST--
2Lazy objects: resetAsLazy*() calls destructor of pre-existing object, unless SKIP_DESTRUCTOR flag is used
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        var_dump(__METHOD__);
15    }
16}
17
18$reflector = new ReflectionClass(C::class);
19
20print "# Ghost:\n";
21
22$obj = new C();
23print "In makeLazy\n";
24$reflector->resetAsLazyGhost($obj, function ($obj) {
25    var_dump("initializer");
26    $obj->__construct();
27}, ReflectionClass::SKIP_DESTRUCTOR);
28print "After makeLazy\n";
29
30var_dump($obj->a);
31$obj = null;
32
33print "# Proxy:\n";
34
35$obj = new C();
36print "In makeLazy\n";
37$reflector->resetAsLazyProxy($obj, function ($obj) {
38    var_dump("initializer");
39    return new C();
40}, ReflectionClass::SKIP_DESTRUCTOR);
41print "After makeLazy\n";
42
43var_dump($obj->a);
44$obj = null;
45
46?>
47--EXPECT--
48# Ghost:
49In makeLazy
50After makeLazy
51string(11) "initializer"
52int(1)
53string(13) "C::__destruct"
54# Proxy:
55In makeLazy
56After makeLazy
57string(11) "initializer"
58int(1)
59string(13) "C::__destruct"
60