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