3v4l.org

run code in 500+ PHP versions simultaneously
<?php #[AllowDynamicProperties] class C { public $_; public function __set($name, $value) { var_dump(__METHOD__); $this->$name = $value * 2; } } $rc = new ReflectionClass(C::class); $obj = $rc->newLazyProxy(function () { echo "init\n"; return new C; }); $obj->prop = 1; var_dump($obj->prop);
Output for 8.4.7 - 8.4.28, 8.5.0 - 8.5.13, 8.6.0
string(8) "C::__set" init int(2)
Output for 8.4.1 - 8.4.6
string(8) "C::__set" init string(8) "C::__set" int(4)
Output for 8.1.34, 8.2.0 - 8.2.36, 8.3.0 - 8.3.37
Fatal error: Uncaught Error: Call to undefined method ReflectionClass::newLazyProxy() in /in/uFRia:15 Stack trace: #0 {main} thrown in /in/uFRia on line 15
Process exited with code 255.

preferences:
15.46 ms | 1170 KiB | 6 Q