3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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"; // 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 5.2.14 - 5.6.28, 7.0.0 - 7.1.0
PHP Exception `Exception`: Just invoking the exception handler Stack trace: #0 /in/hiHZN(48): a(string) #1 {main} thrown in /in/hiHZN on line 52
Output for hhvm-3.12.0
Fatal error: Uncaught exception 'Exception' with message 'Just invoking the exception handler' in /in/hiHZN:52 Stack trace: #0 /in/hiHZN(48): a() #1 {main} PHP Exception `Exception`: Just invoking the exception handler Stack trace: #0 /in/hiHZN(48): a(string) #1 {main} thrown in /in/hiHZN on line 52
Output for hhvm-3.10.0

Process exited with code 153.