1--TEST--
2Lazy objects: clone: initializer exception
3--FILE--
4<?php
5
6class C {
7    public $a = 1;
8
9    public function __construct() {
10    }
11
12    public function __destruct() {
13        var_dump(__METHOD__);
14    }
15}
16
17function test(string $name, object $obj) {
18    printf("# %s:\n", $name);
19
20    $reflector = new ReflectionClass($obj::class);
21
22    try {
23        $clone = clone $obj;
24    } catch (\Exception $e) {
25        printf("%s: %s\n", $e::class, $e->getMessage());
26    }
27
28    var_dump($reflector->isUninitializedLazyObject($obj));
29    var_dump($obj);
30}
31
32$reflector = new ReflectionClass(C::class);
33
34$obj = $reflector->newLazyGhost(function ($obj) {
35    throw new \Exception('initializer');
36});
37
38test('Ghost', $obj);
39
40$obj = $reflector->newLazyProxy(function ($obj) {
41    throw new \Exception('initializer');
42});
43
44test('Proxy', $obj);
45
46--EXPECTF--
47# Ghost:
48Exception: initializer
49bool(true)
50lazy ghost object(C)#%d (0) {
51}
52# Proxy:
53Exception: initializer
54bool(true)
55lazy proxy object(C)#%d (0) {
56}
57