3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Casting with integer or int are equivalent and work fine var_dump((integer) 2); var_dump((int) 3); // int as a return type hint works function returnFour() : int { // casting as integer satisfies the int return type hint return (integer) 4; } // int as a parmater type hit works function addOne(int $var2) : int { return $var2 + 1; } // integer as a return type hint does NOT work // Error function returnFive() : integer { return (integer) 5; } // integer as a parameter type hint does NOT work // Error function addOneInteger(integer $var1) : int { return $var1 + 1; } // the first two work $var1 = returnFour(); var_dump($var1); $var2 = addOne(8); var_dump($var2); // these ones fail $var3 = returnFive(7); var_dump($var3); $var4 = addOneInteger(); var_dump($var4);
Output for 7.0.0 - 7.1.10
int(2) int(3) int(4) int(9) Fatal error: Uncaught TypeError: Return value of returnFive() must be an instance of integer, integer returned in /in/gv4n3:24 Stack trace: #0 /in/gv4n3(42): returnFive(7) #1 {main} thrown in /in/gv4n3 on line 24
Process exited with code 255.
Output for hhvm-3.22.0
int(2) int(3) int(4) int(9) Fatal error: Uncaught TypeError: Value returned from function returnFive() must be of type integer, int given in /in/gv4n3:-1 Stack trace: #0 /in/gv4n3(-1): returnFive() #1 {main}
Process exited with code 255.
Output for hhvm-3.18.5 - 3.21.3
int(2) int(3) int(4) int(9) Fatal error: Uncaught TypeError: Value returned from function returnFive() must be of type integer, int given in /in/gv4n3:24 Stack trace: #0 /in/gv4n3(42): returnFive() #1 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting '{' in /in/gv4n3 on line 8
Process exited with code 255.