1--TEST--
2Lazy objects: json_encode initializes object
3--FILE--
4<?php
5
6class C {
7    public int $a;
8    public function __construct() {
9        var_dump(__METHOD__);
10        $this->a = 1;
11    }
12}
13
14$reflector = new ReflectionClass(C::class);
15
16print "# Ghost:\n";
17
18$obj = $reflector->newLazyGhost(function ($obj) {
19    var_dump("initializer");
20    $obj->__construct();
21});
22
23var_dump(json_encode($obj));
24
25print "# Proxy:\n";
26
27$obj = $reflector->newLazyProxy(function ($obj) {
28    var_dump("initializer");
29    return new C();
30});
31
32var_dump(json_encode($obj));
33
34--EXPECTF--
35# Ghost:
36string(11) "initializer"
37string(14) "C::__construct"
38string(7) "{"a":1}"
39# Proxy:
40string(11) "initializer"
41string(14) "C::__construct"
42string(7) "{"a":1}"
43