@ 2015-10-22T19:07:59Z <?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);
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 int(10)
object(TypeError)#1 (7) {
["message":protected]=>
string(96) "double(): Argument #1 ($value) must be of type int, 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 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 int(10)
object(TypeError)#1 (7) {
["message":protected]=>
string(99) "Argument 1 passed to double() must be of the type int, 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 7.0.0 - 7.0.33 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 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.4.0 - 5.4.45 , 5.5.0 - 5.5.38 , 5.6.0 - 5.6.40 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 . preferences:dark mode live preview
263.29 ms | 402 KiB | 372 Q