@ 2024-12-03T19:52:47Z <?php
class X {
public string $y;
}
$x = new X();
$x->y = 'hello world';
$r = new ReflectionClass('X');
$z = $r->newLazyProxy(fn() => $x);
var_dump($x, spl_object_hash($x), spl_object_id($x));
var_dump($z, spl_object_hash($z), spl_object_id($z));
$_ = $z->y;
var_dump($x, spl_object_hash($x), spl_object_id($x));
var_dump($z, spl_object_hash($z), spl_object_id($z));
var_dump(get_class($x), get_class($z));
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.4.1 - 8.4.13 object(X)#1 (1) {
["y"]=>
string(11) "hello world"
}
string(32) "00000000000000010000000000000000"
int(1)
lazy proxy object(X)#4 (0) {
["y"]=>
uninitialized(string)
}
string(32) "00000000000000040000000000000000"
int(4)
object(X)#1 (1) {
["y"]=>
string(11) "hello world"
}
string(32) "00000000000000010000000000000000"
int(1)
lazy proxy object(X)#4 (1) {
["instance"]=>
object(X)#1 (1) {
["y"]=>
string(11) "hello world"
}
}
string(32) "00000000000000040000000000000000"
int(4)
string(1) "X"
string(1) "X"
Output for 8.1.32 , 8.2.25 - 8.2.29 , 8.3.5 - 8.3.26 Fatal error: Uncaught Error: Call to undefined method ReflectionClass::newLazyProxy() in /in/QEXKP:11
Stack trace:
#0 {main}
thrown in /in/QEXKP on line 11
Process exited with code 255 . preferences:dark mode live preview ace vim emacs key bindings
68.5 ms | 408 KiB | 5 Q