3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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
based on 4OQeZ
Output for 7.0.0 - 7.2.6
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 hhvm-3.22.0
float(2) Notice: A non well formed numeric value encountered in /in/0m9je on line -1 float(2) float(0) float(0) object(__SystemLib\TypeError)#1 (7) { ["message":protected]=> string(69) "Argument 2 passed to add() must be an instance of float, string given" ["string":"__SystemLib\Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0m9je" ["line":protected]=> int(-1) ["trace":"__SystemLib\Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/0m9je" ["line"]=> int(-1) ["function"]=> string(3) "add" ["args"]=> array(2) { [0]=> float(1) [1]=> string(3) "foo" } } } ["previous":"__SystemLib\Error":private]=> NULL }
Output for hhvm-3.18.5 - 3.21.3
float(2) Notice: A non well formed numeric value encountered in /in/0m9je on line 5 float(2) float(0) float(0) object(__SystemLib\TypeError)#1 (7) { ["message":protected]=> string(69) "Argument 2 passed to add() must be an instance of float, string given" ["string":"__SystemLib\Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/0m9je" ["line":protected]=> int(5) ["trace":"__SystemLib\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":"__SystemLib\Error":private]=> NULL }
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/0m9je on line 3
Process exited with code 255.