3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); function AddIntAndFloat(int $a, float $b): int { return (string) $a + $b; } try { echo AddIntAndFloat(1.4,'2'); } catch(TypeError $e) { echo $e->getMessage(), PHP_EOL; } try { echo AddIntAndFloat(1,'2'); } catch(TypeError $e) { echo $e->getMessage(), PHP_EOL; } try { echo AddIntAndFloat(1,1); } catch(TypeError $e) { echo $e->getMessage(), PHP_EOL; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.14
AddIntAndFloat(): Argument #1 ($a) must be of type int, float given, called in /in/q1PAq on line 8 AddIntAndFloat(): Argument #2 ($b) must be of type float, string given, called in /in/q1PAq on line 14 AddIntAndFloat(): Return value must be of type int, float returned
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Argument 1 passed to AddIntAndFloat() must be of the type int, float given, called in /in/q1PAq on line 8 Argument 2 passed to AddIntAndFloat() must be of the type float, string given, called in /in/q1PAq on line 14 Return value of AddIntAndFloat() must be of the type int, float returned
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34
Argument 1 passed to AddIntAndFloat() must be of the type integer, float given, called in /in/q1PAq on line 8 Argument 2 passed to AddIntAndFloat() must be of the type float, string given, called in /in/q1PAq on line 14 Return value of AddIntAndFloat() must be of the type integer, float returned

preferences:
45.86 ms | 409 KiB | 5 Q