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 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(), $exception->getFile(), $exception->getLine(), 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 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.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.10, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
PHP Fatal error: Uncaught exception 'Exception' with message 'Just invoking the exception handler' in /in/fuL33:54 Stack trace: #0 /in/fuL33(50): a(string) #1 {main} thrown in /in/fuL33 on line 54
Output for 5.0.3 - 5.0.4
Notice: Undefined index: args in /in/fuL33 on line 14 Warning: array_map(): Argument #2 should be an array in /in/fuL33 on line 14 Warning: implode(): Bad arguments. in /in/fuL33 on line 26 PHP Fatal error: Uncaught exception 'Exception' with message 'Just invoking the exception handler' in /in/fuL33:54 Stack trace: #0 /in/fuL33(54): a() #1 /in/fuL33(50): a(string) #2 {main} thrown in /in/fuL33 on line 54
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/fuL33 on line 54
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/fuL33 on line 54
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/fuL33 on line 54
Process exited with code 255.

preferences:
226.77 ms | 401 KiB | 312 Q