3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4, 8.3.6
Warning: "integer" will be interpreted as a class name. Did you mean "int"? Write "\integer" to suppress this warning in /in/gv4n3 on line 22 Warning: "integer" will be interpreted as a class name. Did you mean "int"? Write "\integer" to suppress this warning in /in/gv4n3 on line 29 int(2) int(3) int(4) int(9) Fatal error: Uncaught TypeError: returnFive(): Return value must be of type integer, int 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 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: "integer" will be interpreted as a class name. Did you mean "int"? Write "\integer" to suppress this warning in /in/gv4n3 on line 22 Warning: "integer" will be interpreted as a class name. Did you mean "int"? Write "\integer" to suppress this warning in /in/gv4n3 on line 29 int(2) int(3) int(4) int(9) Fatal error: Uncaught TypeError: returnFive(): Return value must be of type integer, int 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 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
int(2) int(3) int(4) int(9) Fatal error: Uncaught TypeError: Return value of returnFive() must be an instance of integer, int 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 7.0.0 - 7.0.24, 7.1.0 - 7.1.20, 7.2.6 - 7.2.33
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.

preferences:
141.41 ms | 403 KiB | 177 Q