3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function foo(int $x): void { echo 'This is fine:', $x, PHP_EOL; } // Good foo(12345); // Bad try { foo(3.1415); } catch (TypeError $ex) { echo $ex->getMessage(), PHP_EOL; } // Also bad, apparently! foo(PHP_INT_MAX + (PHP_INT_MAX >> 1));
Output for 8.0.0 - 8.0.13, 8.1rc1 - rc3
This is fine:12345 foo(): Argument #1 ($x) must be of type int, float given, called in /in/bmLu5 on line 13 Fatal error: Uncaught TypeError: foo(): Argument #1 ($x) must be of type int, float given, called in /in/bmLu5 on line 19 and defined in /in/bmLu5:4 Stack trace: #0 /in/bmLu5(19): foo(1.3835058055282E+19) #1 {main} thrown in /in/bmLu5 on line 4
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.26
This is fine:12345 Argument 1 passed to foo() must be of the type int, float given, called in /in/bmLu5 on line 13 Fatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type int, float given, called in /in/bmLu5 on line 19 and defined in /in/bmLu5:4 Stack trace: #0 /in/bmLu5(19): foo(1.3835058055282E+19) #1 {main} thrown in /in/bmLu5 on line 4
Process exited with code 255.

preferences:
39.12 ms | 461 KiB | 5 Q