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