3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Main { public function run() { echo "Deep item"; } } class Maker { public function getText() { return function () { return new Main(); }; } } class Tester { private $param; public function __constructor($param) { $this->param = $param; } public function go() { $this->param->run(); } } echo "\n instantiate Maker:\n"; $maker = new Maker(); echo "\n instantiate Tester:\n"; $tester = new Tester($maker->getText()); echo "\n Run Tester:\n"; $tester->go();
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
instantiate Maker: instantiate Tester: Run Tester: Fatal error: Uncaught Error: Call to a member function run() on null in /in/HHIrV:30 Stack trace: #0 /in/HHIrV(39): Tester->go() #1 {main} thrown in /in/HHIrV on line 30
Process exited with code 255.
Output for 5.6.0 - 5.6.40
instantiate Maker: instantiate Tester: Run Tester: Fatal error: Call to a member function run() on null in /in/HHIrV on line 30
Process exited with code 255.
Output for 5.5.0 - 5.5.38
instantiate Maker: instantiate Tester: Run Tester: Fatal error: Call to a member function run() on a non-object in /in/HHIrV on line 30
Process exited with code 255.

preferences:
192.88 ms | 401 KiB | 326 Q