PHP Classes

How to Use a PHP Custom Error Handler Class to Show Rich Information About the PHP Errors That Are Happening in an Application Using the Package PHP Error Handler Class: Output details when a PHP error occurs

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-09-10 (2 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
php-errorhandler 4.3MIT/X Consortium ...7.0Debug, Logging, PHP 7
Description 

Author

This package can output details when a PHP error occurs.

It registers class functions to handle PHP errors, exceptions, and fatal errors.

The error handler functions output HTML to display details of the error, like:

- HTTP response status code

- PHP script execution time

- Memory that was used

- Name of the file and number of the line of the code that triggered the error

- Snippet of the code that triggered the error displayed with syntax highlighting

- Backtrace of the functions that called the code that triggered the error

- HTTP server Name, PHP Version, Operating System, remote user IP address, included files

- Global variables

The package can also log the errors to a file, send email messages to the current site administrator about the errors.

The messages can be translated into multiple languages.

It can also keep track of the number of errors triggered by accesses from users of each IP address and ignore the errors if too many errors were triggered by requests from users of the same IP address.

Picture of Thomas Trautner
Name: Thomas Trautner <contact>
Classes: 1 package by
Country: Germany Germany

Instructions

Example

<?php
/* JUST TESTING */

include_once("errorhandler.class.php");

// ADDITIONAL OPTIONS
$php_errorhandler = new ErrorHandler(); // initialize
$php_errorhandler->performance(true); // show performance
$php_errorhandler->showSource(true); // show source code
$php_errorhandler->backtrace(true); // show backtrace
$php_errorhandler->showinfo(true); // show server information
$php_errorhandler->setDebug(false); // debug true = show global variables
$php_errorhandler->logfile('error.log'); // Enable file logging

/* EMAIL ALERTS
* $smtpConfig = [
* 'host' => 'smtp.yourdomain.com',
* 'port' => 587,
* 'encryption' => 'tls', // '', 'tls', 'ssl'
* 'username' => '[email protected]',
* 'password' => 'your-app-password',
* 'from' => '[email protected]',
* 'from_name' => 'Error System',
* 'timeout' => 30
* ];
* $php_errorhandler->mailto('[email protected]', 'en'); // Email alerts serverside
* $php_errorhandler->mailto('[email protected]', 'en',$smtpConfig); // Email alerts with SMTP
*/

// --- INCLUDE/REQUIRE FILES WITH SYNTAX CHECK
//$php_errorhandler->safeInclude('include_file.php'); // FORCES SYNTAX ERROR- COMMENT TO GET ERROR IN LINE 42
// $php_errorhandler->safeRequire('required_file.php'); // FORCES SYNTAX ERROR- COMMENT TO GET ERROR IN LINE 42

echo "Line 34: No errors here<br>";
echo
"Line 35: No errors here<br>";
echo
"Line 36: No errors here<br>";
echo
"Line 37: No errors here<br>";
echo
"Line 38: No errors here<br>";
echo
"Line 39: No errors here<br>";
echo
"Line 40: No errors here<br>";
echo
"Line 41: No errors here<br>";
error_in_line_42; // FORCES ERROR
echo "Line 43: No errors here<br>";
echo
"Line 44: No errors here<br>";
echo
"Line 45: No errors here<br>";
echo
"Line 46: No errors here<br>";
echo
"Line 47: No errors here<br>";
echo
"Line 48: No errors here<br>";


  Files folder image Files (4)  
File Role Description
Plain text file errorhandler.class.php Class errorhandler
Accessible without login Plain text file include_file.php Example test file for include
Accessible without login Plain text file test.php Example testing
Accessible without login Plain text file test2.php Example Include test: missing semicolon

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 0%
Total:0
This week:0