3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sum(float ...$numbers) : float { $intsum = function ($sum, array $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.18, 8.3.0 - 8.3.6
Warning: Undefined variable $intsum in /in/pdmNm on line 9 Fatal error: Uncaught Error: Value of type null is not callable in /in/pdmNm:9 Stack trace: #0 /in/pdmNm(12): {closure}(1.0, Array) #1 /in/pdmNm(15): sum(1.0, 2.0, 3.0, 4.0) #2 {main} thrown in /in/pdmNm on line 9
Process exited with code 255.
Output for 8.0.0 - 8.0.30
Warning: Undefined variable $intsum in /in/pdmNm on line 9 Fatal error: Uncaught Error: Value of type null is not callable in /in/pdmNm:9 Stack trace: #0 /in/pdmNm(12): {closure}(1, Array) #1 /in/pdmNm(15): sum(1, 2, 3, 4) #2 {main} thrown in /in/pdmNm on line 9
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, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Notice: Undefined variable: intsum in /in/pdmNm on line 9 Fatal error: Uncaught Error: Function name must be a string in /in/pdmNm:9 Stack trace: #0 /in/pdmNm(12): {closure}(1, Array) #1 /in/pdmNm(15): sum(1, 2, 3, 4) #2 {main} thrown in /in/pdmNm on line 9
Process exited with code 255.
Output for 7.3.32 - 7.3.33
Fatal error: Uncaught Error: Function name must be a string in /in/pdmNm:9 Stack trace: #0 /in/pdmNm(12): {closure}(1, Array) #1 /in/pdmNm(15): sum(1, 2, 3, 4) #2 {main} thrown in /in/pdmNm on line 9
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Parse error: syntax error, unexpected ':', expecting '{' in /in/pdmNm 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/pdmNm on line 3
Process exited with code 255.

preferences:
174.19 ms | 401 KiB | 228 Q