Skip to content

Instantly share code, notes, and snippets.

@joecritch
Last active June 22, 2017 16:30
Show Gist options
  • Save joecritch/f019096d9dddd60dded74acf7d87be73 to your computer and use it in GitHub Desktop.
Save joecritch/f019096d9dddd60dded74acf7d87be73 to your computer and use it in GitHub Desktop.
PHP redbox for errors
<?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");
?>
.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;
}
@joecritch
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment