PHPackages                             iquipedigital/php-error-handler - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. iquipedigital/php-error-handler

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

iquipedigital/php-error-handler
===============================

A simple, environment-aware custom error and exception handler for PHP applications.

00PHP

Since Jun 1Pushed 11mo agoCompare

[ Source](https://github.com/iquipe/php-error-handler)[ Packagist](https://packagist.org/packages/iquipedigital/php-error-handler)[ RSS](/packages/iquipedigital-php-error-handler/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Error Handler
=================

[](#php-error-handler)

[](https://opensource.org/licenses/MIT)[](https://www.php.net/)[](https://www.google.com/search?q=https://packagist.org/packages/acme/php-error-handler)

A simple, lightweight, and environment-aware custom error and exception handler for PHP applications. It captures all PHP errors and uncaught exceptions, logs them to files, and displays them cleanly during development without exposing sensitive information in production.

Key Features
------------

[](#key-features)

- **Comprehensive Capture**: Catches all levels of PHP errors, including `E_NOTICE`, `E_WARNING`, and fatal errors.
- **Exception Handling**: Gracefully handles any uncaught `Throwable` (Exceptions and Errors).
- **Environment-Aware**: Differentiates between `development` and `production` environments.
    - In `development`, it displays detailed, formatted error messages in the browser.
    - In `production`, it hides sensitive details and shows a generic error message.
- **Robust Logging**: Logs all errors and exceptions to separate, readable files (`error.log` and `exception.log`) regardless of the environment.
- **Easy Integration**: Install via Composer and enable with a single line of code.
- **Configurable**: Easily set the application environment and the path for log files.

Installation
------------

[](#installation)

This library is intended to be installed via [Composer](https://getcomposer.org/).

1. Open your terminal and navigate to your project's root directory.
2. Run the following command:

```
composer require iquipedigital/php-error-handler
```

How to Use
----------

[](#how-to-use)

The error handler should be registered at the very beginning of your application's lifecycle. This ensures it can catch any errors that happen during script execution. The best place for this is your main entry point, such as `index.php` or a bootstrap file.

### Basic Usage (Development Example)

[](#basic-usage-development-example)

In your `index.php`:

```
