Skip to content

Instantly share code, notes, and snippets.

@joecritch joecritch/_redbox.php
Last active Jun 22, 2017

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Jun 22, 2017

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
You can’t perform that action at this time.