3v4l.org

run code in 300+ PHP versions simultaneously
<?php function exceptionHandler($exception) { // these are our templates $traceline = "#%s %s(%s): %s(%s)"; $msg = "PHP Exception `%s`: %s\nStack trace:\n%s\n thrown in %s on line %s"; $msg = "PHP Fatal error: Uncaught exception '%s' with message '%s' in %s:%s\nStack trace:\n%s\n thrown in %s on line %s"; // alter your trace as you please, here $trace = $exception->getTrace(); foreach ($trace as $key => $stackPoint) { // I'm converting arguments to their type // (prevents passwords from ever getting logged as anything other than 'string') $trace[$key]['args'] = array_map('gettype', $trace[$key]['args']); } // build your tracelines $result = array(); foreach ($trace as $key => $stackPoint) { $result[] = sprintf( $traceline, $key, $stackPoint['file'], $stackPoint['line'], $stackPoint['function'], implode(', ', $stackPoint['args']) ); } // trace always ends with {main} $result[] = '#' . ++$key . ' {main}'; // write tracelines into main template $msg = sprintf( $msg, get_class($exception), $exception->getMessage(), implode("\n", $result), $exception->getFile(), $exception->getLine() ); // log or echo as you please print $msg; } set_exception_handler("exceptionHandler"); a("1"); function a($i) { throw new Exception("Just invoking the exception handler"); }
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ArgumentCountError: 8 arguments are required, 6 given in /in/9kKG0:34 Stack trace: #0 /in/9kKG0(34): sprintf('PHP Fatal error...', 'Exception', 'Just invoking t...', '#0 /in/9kKG0(49...', '/in/9kKG0', 53) #1 [internal function]: exceptionHandler(Object(Exception)) #2 {main} thrown in /in/9kKG0 on line 34
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught ArgumentCountError: 8 arguments are required, 6 given in /in/9kKG0:40 Stack trace: #0 /in/9kKG0(40): sprintf('PHP Fatal error...', 'Exception', 'Just invoking t...', '#0 /in/9kKG0(49...', '/in/9kKG0', 53) #1 [internal function]: exceptionHandler(Object(Exception)) #2 {main} thrown in /in/9kKG0 on line 40
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.12 - 7.3.33, 7.4.0 - 7.4.33
Warning: sprintf(): Too few arguments in /in/9kKG0 on line 40
Output for 5.0.0 - 5.0.2, 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
Warning: sprintf(): Too few arguments in /in/9kKG0 on line 41
Output for 5.0.3 - 5.0.4
Notice: Undefined index: args in /in/9kKG0 on line 15 Warning: array_map(): Argument #2 should be an array in /in/9kKG0 on line 15 Warning: implode(): Bad arguments. in /in/9kKG0 on line 27 Warning: sprintf(): Too few arguments in /in/9kKG0 on line 41
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/9kKG0 on line 53
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/9kKG0 on line 53
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/9kKG0 on line 53
Process exited with code 255.

preferences:
285.23 ms | 401 KiB | 360 Q