File: reset_as_lazy_ignores_additional_props.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (103 lines) | stat: -rw-r--r-- 1,398 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
--TEST--
Lazy objects: resetAsLazy() ignores additional props
--FILE--
<?php

class A {
    public $a;
}

class B extends A {
    public $b;
}

class C extends A {
    public $a;
    public $c;
}

class D extends A {
    public readonly int $d;
    public function __construct(bool $init = false) {
        if ($init) {
            $this->d = 1;
        }
    }
}

$reflector = new ReflectionClass(A::class);

printf("# B\n");

$obj = new B();
$obj->a = 1;
$obj->b = 2;
$reflector->resetAsLazyGhost($obj, function () {});
var_dump($obj->b);
var_dump($obj);
var_dump($obj->a);
var_dump($obj);

printf("# C\n");

$obj = new C();
$obj->a = 1;
$obj->c = 2;
$reflector->resetAsLazyGhost($obj, function () {});
var_dump($obj->c);
var_dump($obj);
var_dump($obj->a);
var_dump($obj);

printf("# D\n");

$obj = new D();
$obj->a = 1;
$reflector->resetAsLazyGhost($obj, function ($obj) {
    $obj->__construct(true);
});
var_dump($obj->d ?? 'undef');
var_dump($obj);
var_dump($obj->a);
var_dump($obj);

--EXPECTF--
# B
int(2)
lazy ghost object(B)#%d (1) {
  ["b"]=>
  int(2)
}
NULL
object(B)#%d (2) {
  ["a"]=>
  NULL
  ["b"]=>
  int(2)
}
# C
int(2)
lazy ghost object(C)#%d (1) {
  ["c"]=>
  int(2)
}
NULL
object(C)#%d (2) {
  ["a"]=>
  NULL
  ["c"]=>
  int(2)
}
# D
string(5) "undef"
lazy ghost object(D)#%d (0) {
  ["d"]=>
  uninitialized(int)
}
NULL
object(D)#%d (2) {
  ["a"]=>
  NULL
  ["d"]=>
  int(1)
}