Last active
June 22, 2017 16:30
-
-
Save joecritch/f019096d9dddd60dded74acf7d87be73 to your computer and use it in GitHub Desktop.
PHP redbox for errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$errors = array(); | |
function redbox($no, $str, $file, $line) { | |
global $errors; | |
$errors[] = array( | |
'no' => $no, | |
'str' => $str, | |
'file' => $file, | |
'line' => $line, | |
); | |
} | |
set_error_handler("redbox"); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.redbox { | |
overflow-y: auto; | |
position: fixed; | |
background: #e91e00; | |
color: #fff; | |
z-index: 999; | |
top: 0; | |
left: 0; | |
width: 100vw; | |
height: 100vh; | |
display: flex; | |
justify-content: center; | |
align-items: flex-start; | |
} | |
.redbox ul { | |
margin-top: -40px; | |
} | |
.redbox li { | |
padding-top: 40px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This sets a custom error handler, which collects the errors into an associative array, allowing you to output them elsewhere. This UI is similar to the redbox, common in JavaScript, etc. Ensures you have less runtime errors.
This could really do with a stack trace, lol