3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class foo { private $fn; function __construct() { $this->reg(function () { $this->bar(); }); } private function reg(callable $x) { $this->fn = $x; } public function baz() { $this->fn(); } private function bar() { echo 'bar'; } } $foo = new foo; $foo->baz();
based on 1SpUl
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Call to undefined method foo::fn() in /in/scgL8:19 Stack trace: #0 /in/scgL8(29): foo->baz() #1 {main} thrown in /in/scgL8 on line 19
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Fatal error: Call to undefined method foo::fn() in /in/scgL8 on line 19
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Catchable fatal error: Argument 1 passed to foo::reg() must be an instance of callable, instance of Closure given, called in /in/scgL8 on line 9 and defined in /in/scgL8 on line 12
Process exited with code 255.