PHP Classes

How to Implement PHP Error Handling Code that Presents Solutions to Known Problems Using the Package hitilafu: Error handler that displays the error context

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2026-01-31 (22 days ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
hitilafu 1.0The PHP License5PHP 5, Debug, Language
Description 

Author

This package implements an error handler that presents solutions to problems.

It provides a class that registers functions to handle regular PHP errors, fatal error and exceptions.

The class can also register solutions that define text strings that appear in errors triggered when known problems happens.

It will displays on the current page details of the error like:

- Error message

- Error line

- Source code of the script that trigger error near the error line

- Stack trace of the functions that called the code that triggered the error

- Solutions to solve the problem for known errors

- Request variable values

- PHP environment values

Innovation Award
PHP Programming Innovation award nominee
January 2026
Nominee
Vote
When a PHP developer needs to debug an application, often needs to understand and fix errors that may appear when the code is executed.

PHP supports setting error handling functions that can be used to provide more details about the errors and help to fix the errors faster.

This package provides an error handler class that can provide many details about the errors including solutions to known errors.

Manuel Lemos
Picture of Boss Ibrahim Mussa
  Performance   Level  
Name: Boss Ibrahim Mussa <contact>
Classes: 14 packages by
Country: Congo Congo
Age: ???
All time rank: 28901 in Congo Congo
Week rank: 46 Up1 in Congo Congo Equal
Innovation award
Innovation award
Nominee: 6x

Instructions

Example

<?php

/**
 * Hitilafu Error Handler Example
 *
 * This file demonstrates how to use the error handler in your PHP application
 */

use Wepesi\Hitilafu\Hitilafu;

require_once
__DIR__ . '/../vendor/autoload.php';

// Register the error handler and configure it

Hitilafu::register()
    ->
setAppName('My Awesome App')
   
// ->setTheme('dark') // default is 'light'
    // Add custom solutions for specific errors
   
->addSolution(
       
'mysqli_connect',
       
'MySQL Connection Issue',
       
'Make sure your MySQL server is running and the credentials in your configuration file are correct. Check if the MySQL port (default 3306) is open and accessible.',
        [
            [
'text' => 'MySQL Connection Guide', 'url' => 'https://dev.mysql.com/doc/refman/8.0/en/connecting.html'],
            [
'text' => 'Common Connection Errors', 'url' => 'https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html']
        ]
    )
    ->
addSolution(
       
'Composer\Autoload',
       
'Composer Autoload Issue',
       
'Run "composer install" or "composer dump-autoload" to regenerate the autoloader. Make sure composer.json is properly configured.',
        [
            [
'text' => 'Composer Documentation', 'url' => 'https://getcomposer.org/doc/']
        ]
    )
    ->
addSolution(
       
'redis',
       
'Redis Connection Failed',
       
'Ensure Redis server is running on the specified host and port. Check if Redis is installed and the service is active. Verify firewall rules allow connection to Redis port (default 6379).',
        [
            [
'text' => 'Redis Quick Start', 'url' => 'https://redis.io/docs/getting-started/']
        ]
    );

// include a file with syntax errors to test parse error handling
include 'example.php';


Details

Hitilafu - Beautiful PHP Error Handler

A developer-friendly error page renderer inspired by Laravel Ignition, but standalone with no dependencies.

Features

  • Beautiful, modern error pages with dark/light theme
  • Stack trace with code context
  • Intelligent solution suggestions
  • Request and environment information
  • Responsive design
  • Syntax-highlighted code blocks

Installation

composer require wepesi/hitilafu

Usage

<?php
require_once 'vendor/autoload.php';

use Wepesi\Hitilafu\Hitilafu;

// Register the error handler
Hitilafu::register()
    ->setAppName('My Awesome App')
    ->setTheme('dark'); // or 'light'

Custom Solutions

Add custom solutions for specific error patterns:

Hitilafu::register()
    ->addSolution(
        'mysqli_connect',
        'MySQL Connection Issue',
        'Make sure your MySQL server is running and credentials are correct.',
        [
            ['text' => 'MySQL Docs', 'url' => 'https://dev.mysql.com/doc/']
        ]
    );

custom solutions are used based on the application implementation like (plugins, component, models, controllers, ...)

image

Important: Syntax Error Limitations

Why Syntax Errors Can't Be Caught

Syntax errors (parse errors) occur during PHP's compilation phase, BEFORE your code executes. This means:

  1. Same file syntax errors: Cannot be caught because PHP parses the entire file before running it
  2. Included file syntax errors: CAN be caught via `handleShutdown()` when using `include` or `require`

Example

This WON'T work (syntax error in main file):

<?php
Hitilafu::register(); // Handler registered

echo "test"  // Syntax error - handler never runs because file fails to parse

This WILL work (syntax error in included file):

<?php
// index.php
Hitilafu::register(); // Handler registered successfully

include 'bad_file.php'; // If bad_file.php has syntax errors, handler catches it

Testing Syntax Error Handling

To test syntax error you can check the example file where the is a list of custom example already tested.

<?php
Hitilafu::register();

// This will trigger the error handler
include 'example.php'; // Contains syntax errors

example

Error Types Handled

  • Runtime Errors: Division by zero, undefined variables, etc.
  • Exceptions: Uncaught exceptions
  • Fatal Errors: Memory exhaustion, maximum execution time
  • Parse Errors: In included files (NOT in the main file)
  • Warnings & Notices: Converted to ErrorException

Built-in Solutions

The handler provides intelligent solutions for common errors:

  • File not found
  • Database connection errors
  • Undefined variables/functions
  • Class not found
  • Memory exhausted
  • Permission denied
  • And more...

License

Apache2.0 License


Screenshots (2)  
  • assets/Screenshot 2025-12-02 135752.png
  • assets/Screenshot 2025-12-02 153015.png
  Files folder image Files (10)  
File Role Description
Files folder image.github (1 directory)
Files folder imageexample (2 files)
Files folder imagesrc (3 files)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files (10)  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files (10)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files (10)  /  example  
File Role Description
  Accessible without login Plain text file example.php Aux. Auxiliary script
  Accessible without login Plain text file index.php Example Example script

  Files folder image Files (10)  /  src  
File Role Description
  Accessible without login Plain text file ErrorTemplate.php Example Example script
  Plain text file Hitilafu.php Class Class source
  Plain text file HitilafuContract.php Class Class source

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  
 100%
Total:0
This week:0