1--TEST--
2Lazy objects: RFC example 002
3--FILE--
4<?php
5
6class MyClass
7{
8    public function __construct(private int $foo)
9    {
10        // Heavy initialization logic here.
11    }
12
13    public function getFoo()
14    {
15        return $this->foo;
16    }
17}
18
19$reflector = new ReflectionClass(MyClass::class);
20
21$initializer = static function (MyClass $proxy): MyClass {
22    return new MyClass(123);
23};
24
25$object = $reflector->newLazyProxy($initializer);
26
27var_dump($object);
28var_dump($object->getFoo());
29var_dump($object);
30
31?>
32--EXPECTF--
33lazy proxy object(MyClass)#%d (0) {
34  ["foo":"MyClass":private]=>
35  uninitialized(int)
36}
37int(123)
38lazy proxy object(MyClass)#%d (1) {
39  ["instance"]=>
40  object(MyClass)#%d (1) {
41    ["foo":"MyClass":private]=>
42    int(123)
43  }
44}
45