3v4l.org

run code in 300+ PHP versions simultaneously
<?php function error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, $errno, $errno, $errfile, $errline); } set_error_handler('error_handler'); try { echo 5 / 0; } catch(ErrorException $error) { echo new ErrorExceptionHTMLDecorator($error); } /* WARNING Message: Division by zero Code: 2 Line: 71 File: C:\webroot\www\error.php */ class ErrorExceptionHTMLDecorator { protected $error; protected static $levels = array( E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE', E_STRICT => 'STRICT NOTICE', E_RECOVERABLE_ERROR => 'RECOVERABLE ERROR' ); public function __construct(ErrorException $error) { $this->error = $error; } public function render() { $level = isset(self::$levels[$this->error->getSeverity()]) ? self::$levels[$this->error->getSeverity()] : 'Unknown Error'; return sprintf( ' <h4>%s</h4> <strong>Message:</strong> %s<br /> <strong>Code:</strong> %d<br /> <strong>Line:</strong> %s<br /> <strong>File:</strong> %s<br /> ----------------------------------<br /> ', $level, $this->error->getMessage(), $this->error->getCode(), $this->error->getLine(), $this->error->getFile() ); } public function __toString() { return strip_tags($this->render()); } }

preferences:
42.01 ms | 402 KiB | 5 Q