1--TEST--
2Lazy objects: clone of initialized lazy object does not initialize twice
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    $reflector->initializeLazyObject($obj);
18
19    $clone = clone $obj;
20
21    var_dump($reflector->isUninitializedLazyObject($obj));
22    var_dump($obj);
23    var_dump($reflector->isUninitializedLazyObject($clone));
24    var_dump($clone);
25}
26
27$reflector = new ReflectionClass(C::class);
28
29$obj = $reflector->newLazyGhost(function ($obj) {
30    var_dump("initializer");
31    $obj->__construct();
32});
33
34test('Ghost', $obj);
35
36$obj = $reflector->newLazyProxy(function ($obj) {
37    var_dump("initializer");
38    return new C();
39});
40
41test('Proxy', $obj);
42
43--EXPECTF--
44# Ghost:
45string(11) "initializer"
46bool(false)
47object(C)#%d (1) {
48  ["a"]=>
49  int(1)
50}
51bool(false)
52object(C)#%d (1) {
53  ["a"]=>
54  int(1)
55}
56# Proxy:
57string(11) "initializer"
58bool(false)
59lazy proxy object(C)#%d (1) {
60  ["instance"]=>
61  object(C)#%d (1) {
62    ["a"]=>
63    int(1)
64  }
65}
66bool(false)
67lazy proxy object(C)#%d (1) {
68  ["instance"]=>
69  object(C)#%d (1) {
70    ["a"]=>
71    int(1)
72  }
73}
74