3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sum(float ...$numbers) : float { $intsum = function ($sum, float ...$numbers) { $number = array_shift($numbers); $sum += $number; return $intsum($numbers, $sum); }; return $intsum(0, $numbers); } echo sum(1, 2, 3, 4); echo PHP_EOL; echo sum(1.5, 2, 3, 4); echo PHP_EOL; try { sum('a', 'b', 'c'); } catch (Error $e) { echo $e->getMessage(); }
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Fatal error: Uncaught TypeError: {closure}(): Argument #2 must be of type float, array given, called in /in/BPmgq on line 12 and defined in /in/BPmgq:5 Stack trace: #0 /in/BPmgq(12): {closure}(0, Array) #1 /in/BPmgq(15): sum(1.0, 2.0, 3.0, 4.0) #2 {main} thrown in /in/BPmgq on line 5
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Fatal error: Uncaught TypeError: {closure}(): Argument #2 must be of type float, array given, called in /in/BPmgq on line 12 and defined in /in/BPmgq:5 Stack trace: #0 /in/BPmgq(12): {closure}(0, Array) #1 /in/BPmgq(15): sum(1, 2, 3, 4) #2 {main} thrown in /in/BPmgq on line 5
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
Fatal error: Uncaught TypeError: Argument 2 passed to {closure}() must be of the type float, array given, called in /in/BPmgq on line 12 and defined in /in/BPmgq:5 Stack trace: #0 /in/BPmgq(12): {closure}(0, Array) #1 /in/BPmgq(15): sum(1, 2, 3, 4) #2 {main} thrown in /in/BPmgq on line 5
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Parse error: syntax error, unexpected ':', expecting '{' in /in/BPmgq on line 3
Process exited with code 255.
Output for 5.5.24 - 5.5.35
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/BPmgq on line 3
Process exited with code 255.

preferences:
143.46 ms | 401 KiB | 184 Q