3v4l.org

run code in 300+ PHP versions simultaneously
<?php function add(float $a, float $b): float { return $a + $b; } var_dump(add("1", "1")); // float(2) var_dump(add("1", "1foo")); // PHP Notice: A non well formed numeric value encountered // float(2) var_dump((float) "foo"); // float(0) var_dump(floatval("foo")); // float(0) try { var_dump(add("1", "foo")); } catch (Throwable $e) { var_dump($e); } // PHP Fatal error: Uncaught TypeError: Argument 2 passed to add() must be of the type float, string given
Output for 8.1.0 - 8.1.30, 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
float(2) Fatal error: Uncaught TypeError: add(): Argument #2 ($b) must be of type float, string given, called in /in/0m9je on line 9 and defined in /in/0m9je:3 Stack trace: #0 /in/0m9je(9): add(1.0, '1foo') #1 {main} thrown in /in/0m9je on line 3
Process exited with code 255.
Output for 8.0.0 - 8.0.30
float(2) Fatal error: Uncaught TypeError: add(): Argument #2 ($b) must be of type float, string given, called in /in/0m9je on line 9 and defined in /in/0m9je:3 Stack trace: #0 /in/0m9je(9): add(1, '1foo') #1 {main} thrown in /in/0m9je on line 3
Process exited with code 255.
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
float(2) Notice: A non well formed numeric value encountered in /in/0m9je on line 3 float(2) float(0) float(0) object(TypeError)#1 (7) { ["message":protected]=> string(98) "Argument 2 passed to add() must be of the type float, string given, called in /in/0m9je on line 17" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0m9je" ["line":protected]=> int(3) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0m9je" ["line"]=> int(17) ["function"]=> string(3) "add" ["args"]=> array(2) { [0]=> float(1) [1]=> string(3) "foo" } } } ["previous":"Error":private]=> NULL }
Output for 7.3.32 - 7.3.33
float(2) float(2) float(0) float(0) object(TypeError)#1 (7) { ["message":protected]=> string(98) "Argument 2 passed to add() must be of the type float, string given, called in /in/0m9je on line 17" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0m9je" ["line":protected]=> int(3) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0m9je" ["line"]=> int(17) ["function"]=> string(3) "add" ["args"]=> array(2) { [0]=> float(1) [1]=> string(3) "foo" } } } ["previous":"Error":private]=> NULL }

preferences:
96.73 ms | 413 KiB | 5 Q