1--TEST--
2Lazy objects: serialize() a lazy object that previously failed to initialize, with SKIP_INITIALIZATION_ON_SERIALIZE
3--FILE--
4<?php
5
6#[AllowDynamicProperties]
7class C {
8    public int $a;
9    public $b;
10}
11
12$reflector = new ReflectionClass(C::class);
13
14function test(string $name, object $obj) {
15    printf("# %s\n", $name);
16
17    $reflector = new ReflectionClass(C::class);
18    try {
19        $reflector->initializeLazyObject($obj);
20    } catch (Exception $e) {
21        printf("%s: %s\n", $e::class, $e->getMessage());
22    }
23
24    try {
25        var_dump(unserialize(serialize($obj)));
26    } catch (Exception $e) {
27        printf("%s: %s\n", $e::class, $e->getMessage());
28    }
29}
30
31$obj = $reflector->newLazyGhost(function ($obj) {
32    throw new \Exception('Initializer');
33}, ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE);
34
35test('Ghost', $obj);
36
37$obj = $reflector->newLazyProxy(function () {
38    throw new \Exception('Initializer');
39}, ReflectionClass::SKIP_INITIALIZATION_ON_SERIALIZE);
40
41test('Proxy', $obj);
42
43?>
44--EXPECTF--
45# Ghost
46Exception: Initializer
47object(C)#%d (1) {
48  ["a"]=>
49  uninitialized(int)
50  ["b"]=>
51  NULL
52}
53# Proxy
54Exception: Initializer
55object(C)#%d (1) {
56  ["a"]=>
57  uninitialized(int)
58  ["b"]=>
59  NULL
60}
61