PHP Classes


Recommend this page to a friend!
  Classes of Francisco Nez   BEH Basic PHP Error Handler Class   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: BEH Basic PHP Error Handler Class
Handle PHP errors displaying them using templates
Author: By
Last change:
Date: 2 years ago
Size: 4,357 bytes


Class file image Download

[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]: [error handler]: [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:

[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


# 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


# 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


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


  • (c) 2020 Walter Francisco Nez Cruz Donate