1--TEST--
2Lazy objects: serialize() does not initialize object if __serialize does observe object state
3--FILE--
4<?php
5
6class C {
7    public int $a;
8    public function __serialize() {
9        return [];
10    }
11}
12
13function test(string $name, object $obj) {
14    printf("# %s:\n", $name);
15
16    $serialized = serialize($obj);
17    $unserialized = unserialize($serialized);
18    var_dump($serialized, $unserialized);
19}
20
21$reflector = new ReflectionClass(C::class);
22
23$obj = $reflector->newLazyGhost(function ($obj) {
24    var_dump("initializer");
25});
26
27test('Ghost', $obj);
28
29$obj = $reflector->newLazyProxy(function ($obj) {
30    var_dump("initializer");
31    return new C();
32});
33
34test('Proxy', $obj);
35
36--EXPECTF--
37# Ghost:
38string(12) "O:1:"C":0:{}"
39object(C)#%d (0) {
40  ["a"]=>
41  uninitialized(int)
42}
43# Proxy:
44string(12) "O:1:"C":0:{}"
45object(C)#%d (0) {
46  ["a"]=>
47  uninitialized(int)
48}
49