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)
}
|