1--TEST--
2Lazy objects: array cast does not initialize 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((array)$obj);
24
25$obj->a = 2;
26var_dump((array)$obj);
27
28print "# Proxy:\n";
29
30$obj = $reflector->newLazyProxy(function ($obj) {
31    var_dump("initializer");
32    return new C();
33});
34
35var_dump((array)$obj);
36
37$obj->a = 2;
38var_dump((array)$obj);
39
40--EXPECTF--
41# Ghost:
42array(0) {
43}
44string(11) "initializer"
45string(14) "C::__construct"
46array(1) {
47  ["a"]=>
48  int(2)
49}
50# Proxy:
51array(0) {
52}
53string(11) "initializer"
54string(14) "C::__construct"
55array(1) {
56  ["a"]=>
57  int(2)
58}
59