3v4l.org

run code in 500+ PHP versions simultaneously
<?php //declare(strict_types = 1); interface FooIface{} class FooClass{} function fooNullable(?string $a,?int $b, ?float $c, ?bool $d, ?FooIface $e, ?FooClass $g) : ?int {} function foo ( string $a, int $b, float $c, bool $d, FooIface $e, FooClass $g) : int {} function printTypes(string $fn) { $reflectionFunction = new \ReflectionFunction($fn); $functionParameters = $reflectionFunction->getParameters(); foreach ($functionParameters as $parameter) { var_dump($parameter->getType()->__toString()); } echo "return:"; var_dump($reflectionFunction->getReturnType()->__toString()); return; } echo " ---not nullable--- "; printTypes('foo'); echo " --nullable-- "; printTypes('fooNullable');
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.31, 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
---not nullable--- string(6) "string" string(3) "int" string(5) "float" string(4) "bool" string(8) "FooIface" string(8) "FooClass" return:string(3) "int" --nullable-- string(7) "?string" string(4) "?int" string(6) "?float" string(5) "?bool" string(9) "?FooIface" string(9) "?FooClass" return:string(4) "?int"
Output for 7.4.0 - 7.4.33
---not nullable--- Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(6) "string" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(3) "int" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(5) "float" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(4) "bool" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(8) "FooIface" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(8) "FooClass" return: Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 19 string(3) "int" --nullable-- Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(6) "string" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(3) "int" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(5) "float" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(4) "bool" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(8) "FooIface" Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 16 string(8) "FooClass" return: Deprecated: Function ReflectionType::__toString() is deprecated in /in/HLdjC on line 19 string(3) "int"
Output for 7.1.0 - 7.1.23, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33
---not nullable--- string(6) "string" string(3) "int" string(5) "float" string(4) "bool" string(8) "FooIface" string(8) "FooClass" return:string(3) "int" --nullable-- string(6) "string" string(3) "int" string(5) "float" string(4) "bool" string(8) "FooIface" string(8) "FooClass" return:string(3) "int"
Output for 5.6.38, 7.0.0 - 7.0.31
Parse error: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /in/HLdjC on line 8
Process exited with code 255.

preferences:
121.57 ms | 1740 KiB | 4 Q