3v4l.org

run code in 300+ PHP versions simultaneously
<?php function volume(int $x, int $y, int $z): int { return $x * $y * $z; } $p = fn(int $z): int => volume(3, 5, $z); // This is a useful and common way to normalize different types of callable // to a single API for reflection purposes. $c = Closure::fromCallable($p); $ref = new ReflectionFunction($c); print $ref->getNumberOfParameters() . PHP_EOL; print $ref->getParameters()[0]->getType() . PHP_EOL; print $ref->getParameters()[0]->getName() . PHP_EOL; print $ref->getReturnType() . PHP_EOL;
Output for 7.4.26, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.4, 8.3.6 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
1 int z int
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 1 int z int
Output for 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
1 Deprecated: Function ReflectionType::__toString() is deprecated in /in/LnDg0 on line 15 int z Deprecated: Function ReflectionType::__toString() is deprecated in /in/LnDg0 on line 18 int
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '$z' (T_VARIABLE), expecting ')' in /in/LnDg0 on line 7
Process exited with code 255.

preferences:
41.82 ms | 1370 KiB | 4 Q