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 git.master, git.master_jit, rfc.property-hooks
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.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.37 ms | 401 KiB | 8 Q