1--TEST--
2Lazy objects: serialize 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(serialize($obj));
24
25print "# Proxy:\n";
26
27$obj = $reflector->newLazyProxy(function ($obj) {
28    var_dump("initializer");
29    return new C();
30});
31
32var_dump(serialize($obj));
33
34
35--EXPECTF--
36# Ghost:
37string(11) "initializer"
38string(14) "C::__construct"
39string(24) "O:1:"C":1:{s:1:"a";i:1;}"
40# Proxy:
41string(11) "initializer"
42string(14) "C::__construct"
43string(24) "O:1:"C":1:{s:1:"a";i:1;}"
44