3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * @param Foo|callable $x * @return string */ function process(callable $x): string { return $x(); } class Foo { public function __invoke(): string { return 'I know kung fu!'; } } echo process(new Foo()); echo process(function(): int { return 42; });
Output for 8.2.0 - 8.2.24, 8.3.0 - 8.3.12
I know kung fu! Fatal error: Uncaught TypeError: process(): Return value must be of type string, int returned in /in/4Ncgj:11 Stack trace: #0 /in/4Ncgj(23): process(Object(Closure)) #1 {main} thrown in /in/4Ncgj on line 11
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.29
I know kung fu! Fatal error: Uncaught TypeError: process(): Return value must be of type string, int returned in /in/4Ncgj:11 Stack trace: #0 /in/4Ncgj(25): process(Object(Closure)) #1 {main} thrown in /in/4Ncgj on line 11
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
I know kung fu! Fatal error: Uncaught TypeError: Return value of process() must be of the type string, int returned in /in/4Ncgj:11 Stack trace: #0 /in/4Ncgj(25): process(Object(Closure)) #1 {main} thrown in /in/4Ncgj on line 11
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33
I know kung fu! Fatal error: Uncaught TypeError: Return value of process() must be of the type string, integer returned in /in/4Ncgj:11 Stack trace: #0 /in/4Ncgj(25): process(Object(Closure)) #1 {main} thrown in /in/4Ncgj on line 11
Process exited with code 255.
Output for 5.6.0 - 5.6.29
Warning: Unsupported declare 'strict_types' in /in/4Ncgj on line 3 Parse error: syntax error, unexpected ':', expecting '{' in /in/4Ncgj on line 9
Process exited with code 255.

preferences:
70.91 ms | 411 KiB | 5 Q