3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Foo { public function display() { $cb = self::fooStaticMethod(); call_user_func($cb, $this); } public static function fooStaticMethod() { return function (Foo $foo) { $foo->fooMethod(); }; } private function fooMethod() { var_dump('foo'); } } class Bar extends Foo { } $foo = new Foo(); $foo->display(); $bar = new Bar(); $bar->display();
based on 7dtUA
Output for 5.4.10 - 5.4.29, 7.0.0 - 7.2.0
string(3) "foo" string(3) "foo"
Output for 5.4.30 - 5.6.28
string(3) "foo" Fatal error: Call to private method Foo::fooMethod() from context 'Bar' in /in/diTRh on line 15
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Fatal error: Call to private method Foo::fooMethod() from context '' in /in/diTRh on line 15
Process exited with code 255.