1--TEST--
2Lazy objects: Convertion to array
3--FILE--
4<?php
5
6class C {
7    public int $a;
8    public $b;
9
10    public function __construct() {
11        $this->a = 1;
12        $this->b = 2;
13    }
14}
15
16function test(string $name, object $obj) {
17    printf("# %s\n", $name);
18
19    $reflector = new ReflectionClass(C::class);
20    $reflector->getProperty('a')->setRawValueWithoutLazyInitialization($obj, 3);
21
22    $a = [];
23    // Converts $obj to array internally
24    array_splice($a, 0, 0, $obj);
25    var_dump($a, $obj);
26
27    $reflector->initializeLazyObject($obj);
28
29    $a = [];
30    array_splice($a, 0, 0, $obj);
31    var_dump($a, $obj);
32}
33
34$reflector = new ReflectionClass(C::class);
35$obj = $reflector->newLazyGhost(function ($obj) {
36    $obj->__construct();
37});
38
39test('Ghost', $obj);
40
41$obj = $reflector->newLazyProxy(function () {
42    return new C();
43});
44
45test('Proxy', $obj);
46
47?>
48--EXPECTF--
49# Ghost
50array(1) {
51  [0]=>
52  int(3)
53}
54lazy ghost object(C)#%d (1) {
55  ["a"]=>
56  int(3)
57}
58array(2) {
59  [0]=>
60  int(1)
61  [1]=>
62  int(2)
63}
64object(C)#%d (2) {
65  ["a"]=>
66  int(1)
67  ["b"]=>
68  int(2)
69}
70# Proxy
71array(1) {
72  [0]=>
73  int(3)
74}
75lazy proxy object(C)#%d (1) {
76  ["a"]=>
77  int(3)
78}
79array(2) {
80  [0]=>
81  int(1)
82  [1]=>
83  int(2)
84}
85lazy proxy object(C)#%d (1) {
86  ["instance"]=>
87  object(C)#%d (2) {
88    ["a"]=>
89    int(1)
90    ["b"]=>
91    int(2)
92  }
93}
94