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