BEH Basic PHP Error Handler Class: Handle PHP errors displaying them using templates

Recommend this page to a friend!
  Info   View files Example   View files View files (34)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2020-10-27 (1 month ago) RSS 2.0 feedNot enough user ratingsTotal: 36 All time: 10,006 This week: 195Up
Version License PHP version Categories
beh-basic-error-hand 1.0GNU General Publi...5PHP 5, Debug, Language
Description Author

This class can handle PHP errors displaying them using templates,

It can register class functions as error handlers that will be called when it happens a regular PHP error, an exception or when the a PHP script exits.

The handler function can load a given template script that will be used to display details of the error like the error message, the file and the line of the script that triggered the error and a backtrace of the functions that were called before reaching the line of code that caused the error.

The error details may also be outputted in JSON format to be able to serve the details to browser side handlers that retrieve the error details via AJAX requests.

A separate configuration script is read by the class to define if the the class will output the error details in HTML or plain text, and the template that will be used as skin to render the error details in a Web page.

Picture of Francisco Nez
  Performance   Level  
Name: Francisco Nez <contact>
Classes: 1 package by
Country: Panama Panama
Age: 34
All time rank: 43673 in Panama Panama
Week rank: 509 Up1 in Panama Panama Up

 

Details

[BEH] Basic Error Handler (SA) for PHP

GitHub license State <!-- __SEMANTIC_VERSION_LINE__ --> GitHub issues Minimum PHP version

Acronym: [BEH].

Name: Basic Htaccess Error Handler.

Dependencies: Stand Alone / PHP v7.4.

What does [BEH] do?

[BEH] is a very simple PHP [error handler] implementation that throws [ErrorException] exceptions instead of using the default PHP error handling behaviour. This means that all runtime errors including Fatal are presented to the developer in the form of an exception. It also means that any unhandled errors are delivered to a single point: the global exception handler. also includes support for login errors with [error document]

[error document]: https://httpd.apache.org/docs/2.4/es/custom-error.html [error handler]: http://php.net/set_error_handler [errorexception]: http://php.net/ErrorException

Why use [BEH]?

Developers need the ability to decide how their code behaves when an error occurs. Exceptions offer the only truly consistent way to report and recover from errors in PHP.

This method of handling errors has proven to be extremely effective. Similar strategies are used in major PHP frameworks such as [Laravel]. [BEH] is a standalone implementation that can be used for any project, and not required third party library or software.

Help to improve [BEH]?

if you want to collaborate with the development of the library; You can express your ideas or report any situation related to this in: https://github.com/arcanisgk/BEH-Basic-Error-Handler/issues

[BEH] Configuration:

  • .htaccess: for Apache Version > 2.4.
  • .user.ini: for CGI/FPM/FastCGI.
  • error_conf.php: common configuration.

Note: not tested in NGINX

Custom [BEH] for PHP And Server Error

It must be configured manually in: .htaccess, .user.ini and conf.json depending on the scenario or desired host configuration; let's leave some examples:

  1. Single host server.
  2. Virtual Host and name of the github project.
  3. Development with Xampp in Locally

.htaccess

# php_value auto_prepend_file "/var/www/html/error/init_error.php"
# php_value auto_prepend_file "/var/www/virtual-hostc/git-hub-project-name/error/init_error.php"
php_value auto_prepend_file "C:/xampp/htdocs/error/error_init.php"

Note: because of dependencies you must set the configuration inside <IfModule mod_php7.c> to work correctly; .htaccess file have an example

.user.ini

# auto_prepend_file = "/var/www/html/error/init_error.php"
# auto_prepend_file = "/var/www/virtual-host/git-hub-project-name/error/init_error.php"
auto_prepend_file = "C:/xampp/htdocs/error/error_init.php"

note: .user.ini files not use php_value statement.

Error Server must be setting up with directive in .htaccess file:

ErrorDocument 400 /error/error_server.php

Error_conf.php

skin of [BEH] must be: basic, bs4, custom.

Custom skin [BEH]

you must implement two files skin like. - sk_custom_server_error.php - sk_custom_handler_error.php


Content of skin for [BEH]

you must add the same variable print like basic skin, but you can use your own html design.

Example of [BEH] Runing:

  • Error throw:

Image of Error throw

  • Exception Error:

Image of Exception Error throw

  • Fatal Error:

Image of Fatal Error throw

  • Access Error:

Image of Access Error Control

Contributors

  • (c) 2020 Walter Francisco Nez Cruz icarosnet@gmail.com Donate
  Files folder image Files  
File Role Description
Files folder imageerror (4 files, 1 directory)
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file .user.ini Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file test.php Example Example script

  Files folder image Files  /  error  
File Role Description
Files folder imageskin (6 files, 2 directories)
  Accessible without login Plain text file conf_error.php Conf. Configuration script
  Plain text file handler_error.php Class Error handler class
  Accessible without login Plain text file init_error.php Aux. Auxiliary script
  Accessible without login Plain text file server_error.php Aux. Auxiliary script

  Files folder image Files  /  error  /  skin  
File Role Description
Files folder imagesrc (13 files)
Files folder imagewebfonts (5 files)
  Accessible without login Plain text file sk_basic_handler_error.php Aux. Auxiliary script
  Accessible without login Plain text file sk_basic_server_error.php Aux. Auxiliary script
  Accessible without login Plain text file sk_bs4_handler_error.php Aux. Auxiliary script
  Accessible without login Plain text file sk_bs4_server_error.php Aux. Auxiliary script
  Accessible without login Plain text file sk_custom_handler_error.php Aux. Auxiliary script
  Accessible without login Plain text file sk_custom_server_error.php Aux. Auxiliary script

  Files folder image Files  /  error  /  skin  /  src  
File Role Description
  Accessible without login Plain text file all.min.css Data Auxiliary data
  Accessible without login Plain text file animate.css Data Auxiliary data
  Accessible without login Plain text file bootstrap.css Data Auxiliary data
  Accessible without login Plain text file bootstrap.css.map Data Auxiliary data
  Accessible without login Plain text file bootstrap.js Data Auxiliary data
  Accessible without login Plain text file bootstrap.js.map Data Auxiliary data
  Accessible without login Plain text file destyle.css Data Auxiliary data
  Accessible without login Plain text file error.css Data Auxiliary data
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Image file favicon.png Data Auxiliary data
  Accessible without login Plain text file jquery.min.js Data Auxiliary data
  Accessible without login Plain text file popper.min.js Data Auxiliary data
  Accessible without login Plain text file reset.css Data Auxiliary data

  Files folder image Files  /  error  /  skin  /  webfonts  
File Role Description
  Accessible without login Plain text file fa-brands-400.svg Data Auxiliary data
  Accessible without login Plain text file fa-duotone-900.svg Data Auxiliary data
  Accessible without login Plain text file fa-light-300.svg Data Auxiliary data
  Accessible without login Plain text file fa-regular-400.svg Data Auxiliary data
  Accessible without login Plain text file fa-solid-900.svg Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:36
This week:0
All time:10,006
This week:195Up

For more information send a message to info at phpclasses dot org.