1--TEST--
2Lazy objects: RFC example 003
3--FILE--
4<?php
5
6class MyLazyClass
7{
8    private int $foo;
9
10    public function __construct()
11    {
12        $reflector = new ReflectionClass(self::class);
13        $reflector->resetAsLazyGhost($this, $this->initialize(...), ReflectionClass::SKIP_DESTRUCTOR);
14    }
15
16    public function initialize()
17    {
18        $this->foo = 123;
19    }
20
21    public function getFoo()
22    {
23        return $this->foo;
24    }
25
26    public function __destruct()
27    {
28        var_dump(__METHOD__);
29    }
30}
31
32$object = new MyLazyClass();
33
34var_dump($object);
35var_dump($object->getFoo());
36var_dump($object);
37
38?>
39==DONE==
40--EXPECTF--
41lazy ghost object(MyLazyClass)#%d (0) {
42  ["foo":"MyLazyClass":private]=>
43  uninitialized(int)
44}
45int(123)
46object(MyLazyClass)#%d (1) {
47  ["foo":"MyLazyClass":private]=>
48  int(123)
49}
50==DONE==
51string(23) "MyLazyClass::__destruct"
52