3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php declare(strict_types=1); function double(int $value) { return 2 * $value; } function coerceInt(string $value) : int { return (int)$value; } try{ $a = double(coerceInt("5")); var_dump($a); $a = double("5"); var_dump($a); } catch (Throwable $e) { var_dump($e); }
based on VhnpM
Output for 7.0.0 - 7.2.0
int(10) object(TypeError)#1 (7) { ["message":protected]=> string(103) "Argument 1 passed to double() must be of the type integer, string given, called in /in/Nr2lJ on line 16" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/Nr2lJ" ["line":protected]=> int(4) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/Nr2lJ" ["line"]=> int(16) ["function"]=> string(6) "double" ["args"]=> array(1) { [0]=> string(1) "5" } } } ["previous":"Error":private]=> NULL }
Output for 5.3.19 - 5.6.28
Warning: Unsupported declare 'strict_types' in /in/Nr2lJ on line 2 Parse error: syntax error, unexpected ':', expecting '{' in /in/Nr2lJ on line 9
Process exited with code 255.