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

preferences:
59.58 ms | 404 KiB | 5 Q