Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error code showing #75

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 44 additions & 4 deletions src/php_error.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,29 @@ class ErrorHandler
T_UNSET => 'syntax-function'
);

/**
* A mapping of PHP errors,
* mapped to descriptions of them.
*/
private static $PHP_ERROR_MAPPINGS = array(
E_ERROR => 'E_ERROR',
E_WARNING => 'E_WARNING',
E_PARSE => 'E_PARSE',
E_NOTICE => 'E_NOTICE',
E_CORE_ERROR => 'E_CORE_ERROR',
E_CORE_WARNING => 'E_CORE_WARNING',
E_COMPILE_ERROR => 'E_COMPILE_ERROR',
E_COMPILE_WARNING => 'E_COMPILE_WARNING',
E_USER_ERROR => 'E_USER_ERROR',
E_USER_WARNING => 'E_USER_WARNING',
E_USER_NOTICE => 'E_USER_NOTICE',
E_STRICT => 'E_STRICT',
E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
E_DEPRECATED => 'E_DEPRECATED',
E_USER_DEPRECATED => 'E_USER_DEPRECATED',
E_ALL => 'E_ALL'
);

/**
* A list of methods which are known to call the autoloader,
* but should not error, if the class is not found.
Expand Down Expand Up @@ -1142,6 +1165,7 @@ public static function identifyTypeHTML( $arg, $recurseLevels=1 ) {
private $defaultErrorReportingOff;
private $applicationRoot;
private $serverName;
private $showErrorCode;

private $catchClassNotFound;
private $catchSurpressedErrors;
Expand Down Expand Up @@ -1226,6 +1250,8 @@ public static function identifyTypeHTML( $arg, $recurseLevels=1 ) {
* - enable_saving Can be true or false. When true, saving files is enabled, and when false, it is disabled.
* Defaults to true!
*
* - show_error_code Can be true or false. When true php error codes are shown in the actual error message.
* Defaults to false.
* @param options Optional, an array of values to customize this handler.
* @throws Exception This is raised if given an options that does *not* exist (so you know that option is meaningless).
*/
Expand Down Expand Up @@ -1268,6 +1294,7 @@ public function __construct( $options=null ) {

$this->applicationRoot = ErrorHandler::optionsPop( $options, 'application_root' , $_SERVER['DOCUMENT_ROOT'] );
$this->serverName = ErrorHandler::optionsPop( $options, 'server_name' , $_SERVER['SERVER_NAME'] );
$this->showErrorCode = ErrorHandler::optionsPop( $options, 'show_error_code' , false);

/*
* Relative paths might be given for document root,
Expand Down Expand Up @@ -2493,7 +2520,7 @@ public function reportError( $code, $message, $errLine, $errFile, $ex=null ) {

$_SERVER
);
$this->displayError( $message, $srcErrLine, $errFile, $errFileType, $stackTrace, $fileLinesSets, $numFileLines, $dump );
$this->displayError( $message, $srcErrLine, $errFile, $errFileType, $stackTrace, $fileLinesSets, $numFileLines, $dump, $code );

// exit in order to end processing
$this->turnOff();
Expand Down Expand Up @@ -3224,13 +3251,15 @@ private function displayJSInjection() {
* The actual display logic.
* This outputs the error details in HTML.
*/
private function displayError( $message, $errLine, $errFile, $errFileType, $stackTrace, &$fileLinesSets, $numFileLines, $dumpInfo ) {
private function displayError( $message, $errLine, $errFile, $errFileType, $stackTrace, &$fileLinesSets, $numFileLines, $dumpInfo, $code ) {
$applicationRoot = $this->applicationRoot;
$serverName = $this->serverName;
$backgroundText = $this->backgroundText;
$displayLineNumber = $this->displayLineNumber;
$saveUrl = $this->saveUrl;
$isSavingEnabled = $this->isSavingEnabled;
$showErrorCode = $this->showErrorCode;
$codeDescription = ErrorHandler::$PHP_ERROR_MAPPINGS[$code];

/*
* When a query string is not provided,
Expand Down Expand Up @@ -3267,7 +3296,10 @@ function() use (
&$fileLinesSets, $numFileLines,
$displayLineNumber,
$dumpInfo,
$isSavingEnabled
$isSavingEnabled,
$showErrorCode,
$code,
$codeDescription
) {
if ( $backgroundText ) { ?>
<div id="error-wrap">
Expand All @@ -3286,6 +3318,7 @@ function() use (
</span>
</h2>
<h1 id="error-title"><?php echo $message ?></h1>
<?php echo ($showErrorCode ? " <h3 id='error-code'>".$codeDescription." (".$code.")</h3>" : ""); ?>
<div class="error-file-top <?php echo ($fileLinesSets ? 'has_code' : '') ?>">
<h2 id="error-file"><span id="error-linenumber"><?php echo $errLine ?></span> <span id="error-filename" class="<?php echo $errFileType ?>"><?php echo $errFile ?></span></h2>
<?php if ( $isSavingEnabled ) { ?>
Expand Down Expand Up @@ -3597,7 +3630,8 @@ function displayHTML( Closure $head, $body=null, $javascript=null ) {
}

h1,
h2 {
h2,
h3 {
font-family: "Segoe UI Light","Helvetica Neue",'RobotoLight',"Segoe UI","Segoe WP",sans-serif;
font-weight: 100;
line-height: normal;
Expand Down Expand Up @@ -3729,6 +3763,12 @@ function displayHTML( Closure $head, $body=null, $javascript=null ) {
position: relative;
white-space: pre-wrap;
}

#error-code {
font-size: 14px;
margin-bottom: 0px;
margin-top: 0px;
}

<?php
/*
Expand Down