1--TEST--
2Lazy objects: clone initializes object
3--FILE--
4<?php
5
6class C {
7    public $a = 1;
8
9    public function __construct() {
10    }
11}
12
13function test(string $name, object $obj) {
14    printf("# %s:\n", $name);
15
16    $reflector = new ReflectionClass($obj::class);
17    $clone = clone $obj;
18
19    var_dump($reflector->isUninitializedLazyObject($obj));
20    var_dump($obj);
21    var_dump($reflector->isUninitializedLazyObject($clone));
22    var_dump($clone);
23}
24
25$reflector = new ReflectionClass(C::class);
26
27$obj = $reflector->newLazyGhost(function ($obj) {
28    var_dump("initializer");
29    $obj->__construct();
30});
31
32test('Ghost', $obj);
33
34$obj = $reflector->newLazyProxy(function ($obj) {
35    var_dump("initializer");
36    return new C();
37});
38
39test('Proxy', $obj);
40
41--EXPECTF--
42# Ghost:
43string(11) "initializer"
44bool(false)
45object(C)#%d (1) {
46  ["a"]=>
47  int(1)
48}
49bool(false)
50object(C)#%d (1) {
51  ["a"]=>
52  int(1)
53}
54# Proxy:
55string(11) "initializer"
56bool(false)
57lazy proxy object(C)#%d (1) {
58  ["instance"]=>
59  object(C)#%d (1) {
60    ["a"]=>
61    int(1)
62  }
63}
64bool(false)
65lazy proxy object(C)#%d (1) {
66  ["instance"]=>
67  object(C)#%d (1) {
68    ["a"]=>
69    int(1)
70  }
71}
72