I initially started searching for a PHP script which would output PHP errors, to the JavaScript console. As the Default behaviour is just to spit them out anywhere and displace everything else. Can anybody suggest a better approach, ideally they would be neatly stacked at the bottom of the page, in a html table, with full error details ie. line-number, page/script name, error codes and warnings etc.
Ps, this was only ever intended to be used for developement purposes & would be completey removed or commented out in a seperate file once I wished to upload the site onto a live domain/server.
<?php
// ::=> ErrorHandler.php [File];
error_reporting(E_ALL);
class MyError{
{
protected static $collected = array();
public static function getCollectedErrors(){
{
return self::$collected;
}
protected static function addError($key, $error){
{
if (!isset(self::$collected[$key])){
self::$collected[$key] = array();
self::$collected[$key][] = $error;
}
}
// CATCHABLE ERRORS
public static function captureNormal( $number, $message,
$file, $line ){
// Insert all in one table{
// Insert all in one table
$error = array( 'type' => $number,
'message' => $message,
'file' => $file,
'line' => $line
);
// Display content $error variable
self::addError('error', $message . " at " . $file .
':' . $line);
}
public static function captureException($exception){ }
public static function captureException( $exception )
//
Display content $exception variable
{
self::addError('exception', $exception);
// Display content $exception }variable
self::addError('exception', $exception);
// UNCATCHABLE ERRORS
public static function captureShutdown(){
}
// UNCATCHABLE ERRORS
public $errorstatic =function error_get_lastcaptureShutdown( );
{
$error if= error_get_last($error ){;
if( $error ) {
//## IF YOU WANT TO CLEAR ALL BUFFER, UNCOMMENT NEXT LINE:
# ob_end_clean( );
// Display content $error variable
self::addError('shutdown', $error);
}else{
else { self::addError('shutdown', '<none>');
return true; }
}
}
set_error_handler(array( 'MyError', 'captureNormal' ));
set_exception_handler(array( 'MyError', 'captureException' ));
register_shutdown_function(array( 'MyError', 'captureShutdown' ));
?>
<?php
// >>>>>>> Add if Admin Statement in Here & Password Match & Cookie, csrf check.
$errors = MyError::getCollectedErrors(); // This is Linked to ErrorHandlers.php
foreach ($errors as $category => $items) { //::>> This would be better read as foreach($errors as $item => $catergory). change it round later.
echo "<strong class=\"dispLow\"
style=\"display:block;
position:relative;
max-width:248px;
text-wrap:wrap;
z-index:2000;
background:yellow;\">" . $category . ":
</strong><br/>"; // I added class dispLow to the outputted errors with \ escape...
foreach ($items as $error) {
echo "<br>Error:" . $error . $catergory .
$items . $file .
$line . "<br/>" .PHP_EOL;
}
}
?>
Ironically This just happened on a seperate project:
Where This error Spat out inside a Button, bright yellow.
might be a good functionality,
have it initially as a button & press it for more details.
>> Php Error Handler/Logger
>> Echo to Console
>> Register an Error Handler
I have also just installed FirePhp extension/add-on for Firefox Quantum, but I think I need to include files from their github repository into my project for it to work, does anybody know which specific files are necessary and where abouts they should be place, I have read through all the info on the github repo but it doesn't exactly make it very clear which file need to be included? or how you get the add-on to work.