1--TEST--
2Lazy objects: clone is independent of the original object
3--FILE--
4<?php
5
6class SomeObj {
7    public string $foo = 'X';
8    public string $dummy;
9}
10
11function test(string $name, object $obj) {
12    printf("# %s:\n", $name);
13
14    $reflector = new ReflectionClass(SomeObj::class);
15
16    $clonedObj = clone $obj;
17
18    $reflector->initializeLazyObject($obj);
19    $reflector->getProperty('foo')->setRawValueWithoutLazyInitialization($clonedObj, 'Y');
20
21    $reflector->initializeLazyObject($clonedObj);
22
23    var_dump($clonedObj->foo);
24}
25
26$reflector = new ReflectionClass(SomeObj::class);
27
28test('Ghost', $reflector->newLazyGhost(function ($obj) {
29}));
30
31test('Proxy', $reflector->newLazyProxy(function () {
32    return new SomeObj();
33}));
34
35?>
36--EXPECT--
37# Ghost:
38string(1) "Y"
39# Proxy:
40string(1) "Y"
41