3v4l.org

run code in 300+ PHP versions simultaneously
<?php class bla { private $name; function __construct() { $this->name = 'I am this'; echo "We are in\n"; } function dontTouchThis() { return 'not this'; } function touchThis() { return $this->name; } } $lazyBla = (new \ReflectionClass('bla'))->newLazyProxy(function () { return new bla(); }); $whatsThat = $lazyBla->dontTouchThis(); echo $whatsThat . "\n\n"; $whatsThis = $lazyBla->touchThis(); echo $whatsThis . "\n\n"; $bla = new bla;
Output for 8.4.5 - 8.4.13
not this We are in I am this We are in
Output for 8.2.28 - 8.2.29, 8.3.5 - 8.3.26
Fatal error: Uncaught Error: Call to undefined method ReflectionClass::newLazyProxy() in /in/OERUAl:22 Stack trace: #0 {main} thrown in /in/OERUAl on line 22
Process exited with code 255.

preferences:
55.82 ms | 407 KiB | 5 Q