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) var_dump(add("1", "foo")); // 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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
float(2) Fatal error: Uncaught TypeError: add(): Argument #2 ($b) must be of type float, string given, called in /in/4OQeZ on line 9 and defined in /in/4OQeZ:3 Stack trace: #0 /in/4OQeZ(9): add(1.0, '1foo') #1 {main} thrown in /in/4OQeZ on line 3
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 float(2) Fatal error: Uncaught TypeError: add(): Argument #2 ($b) must be of type float, string given, called in /in/4OQeZ on line 9 and defined in /in/4OQeZ:3 Stack trace: #0 /in/4OQeZ(9): add(1.0, '1foo') #1 {main} thrown in /in/4OQeZ 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/4OQeZ on line 9 and defined in /in/4OQeZ:3 Stack trace: #0 /in/4OQeZ(9): add(1, '1foo') #1 {main} thrown in /in/4OQeZ on line 3
Process exited with code 255.
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33
float(2) Notice: A non well formed numeric value encountered in /in/4OQeZ on line 3 float(2) float(0) float(0) Fatal error: Uncaught TypeError: Argument 2 passed to add() must be of the type float, string given, called in /in/4OQeZ on line 16 and defined in /in/4OQeZ:3 Stack trace: #0 /in/4OQeZ(16): add(1, 'foo') #1 {main} thrown in /in/4OQeZ on line 3
Process exited with code 255.
Output for 7.3.32 - 7.3.33
float(2) float(2) float(0) float(0) Fatal error: Uncaught TypeError: Argument 2 passed to add() must be of the type float, string given, called in /in/4OQeZ on line 16 and defined in /in/4OQeZ:3 Stack trace: #0 /in/4OQeZ(16): add(1, 'foo') #1 {main} thrown in /in/4OQeZ on line 3
Process exited with code 255.

preferences:
164.8 ms | 401 KiB | 157 Q