3v4l.org

run code in 500+ PHP versions simultaneously
<?php class Test { public function callback() {} } class Test2 { public function set(callable $callback) {} } $callback = 'Test::callback'; var_dump(is_callable($callback)); $a = new Test2(); $a->set($callback); ?>
Output for 7.3.32, 7.4.26
bool(true)
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
bool(false) Fatal error: Uncaught TypeError: Test2::set(): Argument #1 ($callback) must be of type callable, string given, called in /in/ilbYM on line 14 and defined in /in/ilbYM:6 Stack trace: #0 /in/ilbYM(14): Test2->set('Test::callback') #1 {main} thrown in /in/ilbYM on line 6
Process exited with code 255.
Output for 7.2.0 - 7.2.34, 7.3.0 - 7.3.31, 7.3.33, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
bool(true) Deprecated: Non-static method Test::callback() should not be called statically in /in/ilbYM on line 6

preferences:
38.02 ms | 1153 KiB | 15 Q