3v4l.org

run code in 300+ 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.33, 8.2.3 - 8.2.29, 8.3.5 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
== 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
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
91.57 ms | 407 KiB | 5 Q