3v4l.org

run code in 300+ PHP versions simultaneously
<?php function foo(int $integer): int { return $integer; } try { var_dump(foo(1)); } catch (TypeError $e) { echo "Exception! "; var_dump($e); } try { var_dump(foo("1")); } catch (TypeError $e) { echo "Exception! "; var_dump($e); } try { var_dump(foo("a")); } catch (TypeError $e) { echo "Exception! "; var_dump($e); } try { var_dump(foo("0x0F")); } catch (TypeError $e) { echo "Exception! "; var_dump($e); } try { var_dump(foo(0x0F)); } catch (TypeError $e) { echo "Exception! "; var_dump($e); }
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(1) int(1) Exception! object(TypeError)#1 (7) { ["message":protected]=> string(95) "foo(): Argument #1 ($integer) must be of type int, string given, called in /in/H28Ge on line 20" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/H28Ge" ["line":protected]=> int(3) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/H28Ge" ["line"]=> int(20) ["function"]=> string(3) "foo" ["args"]=> array(1) { [0]=> string(1) "a" } } } ["previous":"Error":private]=> NULL } Exception! object(TypeError)#2 (7) { ["message":protected]=> string(95) "foo(): Argument #1 ($integer) must be of type int, string given, called in /in/H28Ge on line 27" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/H28Ge" ["line":protected]=> int(3) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/H28Ge" ["line"]=> int(27) ["function"]=> string(3) "foo" ["args"]=> array(1) { [0]=> string(4) "0x0F" } } } ["previous":"Error":private]=> NULL } int(15)
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
int(1) int(1) Exception! object(TypeError)#1 (7) { ["message":protected]=> string(96) "Argument 1 passed to foo() must be of the type int, string given, called in /in/H28Ge on line 20" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/H28Ge" ["line":protected]=> int(3) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/H28Ge" ["line"]=> int(20) ["function"]=> string(3) "foo" ["args"]=> array(1) { [0]=> string(1) "a" } } } ["previous":"Error":private]=> NULL } Notice: A non well formed numeric value encountered in /in/H28Ge on line 3 int(0) int(15)
Output for 7.3.32 - 7.3.33
int(1) int(1) Exception! object(TypeError)#1 (7) { ["message":protected]=> string(96) "Argument 1 passed to foo() must be of the type int, string given, called in /in/H28Ge on line 20" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/H28Ge" ["line":protected]=> int(3) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/H28Ge" ["line"]=> int(20) ["function"]=> string(3) "foo" ["args"]=> array(1) { [0]=> string(1) "a" } } } ["previous":"Error":private]=> NULL } int(0) int(15)
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
int(1) int(1) Exception! object(TypeError)#1 (7) { ["message":protected]=> string(100) "Argument 1 passed to foo() must be of the type integer, string given, called in /in/H28Ge on line 20" ["string":"Error":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(9) "/in/H28Ge" ["line":protected]=> int(3) ["trace":"Error":private]=> array(1) { [0]=> array(4) { ["file"]=> string(9) "/in/H28Ge" ["line"]=> int(20) ["function"]=> string(3) "foo" ["args"]=> array(1) { [0]=> string(1) "a" } } } ["previous":"Error":private]=> NULL } Notice: A non well formed numeric value encountered in /in/H28Ge on line 3 int(0) int(15)
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
Parse error: syntax error, unexpected ':', expecting '{' in /in/H28Ge on line 3
Process exited with code 255.

preferences:
215.7 ms | 402 KiB | 255 Q