3v4l.org

run code in 500+ PHP versions simultaneously
<?php function foo(int $a) { var_dump($a); } function define_callbacks() { $string = 'foo'; $lambda = fn(...$args) => foo(...$args); $fcc = foo(...); return [$string, $lambda, $fcc]; } function test_callback($callback) { $callback(1); try { $callback(new class{}); } catch ( TypeError $e ) { echo $e->getMessage(), "\n"; } } [$string, $lambda, $fcc] = define_callbacks(); echo "== String-based ==\n"; test_callback($string); echo "\n== Type-less lambda ==\n"; test_callback($lambda); echo "\n== First-class callable ==\n"; test_callback($fcc);
Output for 8.1.30 - 8.1.34, 8.2.3 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
== String-based == int(1) foo(): Argument #1 ($a) must be of type int, class@anonymous given, called in /in/Q2H2Z on line 18 == Type-less lambda == int(1) foo(): Argument #1 ($a) must be of type int, class@anonymous given, called in /in/Q2H2Z on line 9 == First-class callable == int(1) foo(): Argument #1 ($a) must be of type int, class@anonymous given, called in /in/Q2H2Z on line 18

preferences:
56.14 ms | 749 KiB | 4 Q