3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public $c; public function __construct(callable $c) { $this->c = $c; } public function doCb() { ($this->c)(); } private static function bar() { var_dump(__METHOD__); } } $f = new Foo('Foo::bar'); // fine $f->doCb(); // not fine ($f->c)();
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
string(8) "Foo::bar" Fatal error: Uncaught Error: Call to private method Foo::bar() from global scope in /in/0LHZY:29 Stack trace: #0 {main} thrown in /in/0LHZY on line 29
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
string(8) "Foo::bar" Fatal error: Uncaught Error: Call to private method Foo::bar() from context '' in /in/0LHZY:29 Stack trace: #0 {main} thrown in /in/0LHZY on line 29
Process exited with code 255.

preferences:
101.51 ms | 1445 KiB | 4 Q