3v4l.org

run code in 500+ PHP versions simultaneously
<?php function my_func($arg1 = null, $arg2 = null, $arg3 = null) { if (count(array_filter([$arg1, $arg2, $arg3])) === 0) { throw new Exception('At least one argument must be used'); } echo 'It works!'."\n"; } echo 'First attempt: '; my_func(1); echo "\n".'Second attempt: '; my_func(null, 1); echo "\n".'Third attempt: '; my_func(null, null, 1); echo "\n".'Last attempt: '; my_func();
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.3
First attempt: It works! Second attempt: It works! Third attempt: It works! Last attempt: Fatal error: Uncaught Exception: At least one argument must be used in /in/i8qT0:5 Stack trace: #0 /in/i8qT0(20): my_func() #1 {main} thrown in /in/i8qT0 on line 5
Process exited with code 255.

preferences:
31.49 ms | 1137 KiB | 6 Q