3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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();
based on XvGoc
Output for 7.0.0 - 7.3.0rc4
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.8 - 5.6.28
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.3.19 - 5.5.35
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.