PHPackages                             e2ex/e2ex - 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. e2ex/e2ex

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

e2ex/e2ex
=========

Converts PHP Errors to Exceptions and (optionally) logs PHP Errors, Notices and Warnings with a PSR-3 compatible logger

v0.8.1(13y ago)101.5kMITPHPPHP &gt;=5.3.6

Since Mar 12Pushed 13y ago1 watchersCompare

[ Source](https://github.com/freddiefrantzen/e2ex)[ Packagist](https://packagist.org/packages/e2ex/e2ex)[ Docs](http://github.com/freddiefrantzen/e2ex)[ RSS](/packages/e2ex-e2ex/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

E2EX - Semantic PHP Error handling
==================================

[](#e2ex---semantic-php-error-handling)

A simple library for converting PHP Errors to Exceptions and (optionally) for logging PHP Notices, Warnings and Errors with a PSR-3 compatible logger, such as [monolog](https://github.com/Seldaek/monolog). Enables the unification of application and PHP logs and provides a means to harmonise Error and Exception handling.

Installation with Composer
--------------------------

[](#installation-with-composer)

Add the following line to your [composer.json](http://getcomposer.org/doc/00-intro.md#declaring-dependencies) file:

```
require: "e2ex/e2ex": "0.8.*"

```

Install:

```
$ composer.phar update e2ex/e2ex

```

E2EX should play nice with any PSR-0 autoloader.

Basic Usage
-----------

[](#basic-usage)

Set E2EX to handle all Errors, Warnings and Notices:

```
E2EX\Converter::register(E_ALL);
```

Alternatively, you can pass in a [bitmask](http://php.net/manual/en/errorfunc.constants.php) to set which types should be handled.

```
E2EX\Converter::register(E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_USER_DEPRECATED);
```

Calling register() with no arguments will result in the bitmask being set to the current return value of [error\_reporting()](http://php.net/manual/en/function.error-reporting.php).

Any error types that aren't set to be handled by E2EX will be handled by PHP's built-in error handler, (so long as they fall within the error\_reporting range).

Handling Exceptions
-------------------

[](#handling-exceptions)

Non-fatal Errors will raise an `E2EX\ErrorException`. These can be handled inside try/catch blocks or with a registered [exception handler](http://php.net/manual/en/function.set-exception-handler.php), which can be a static/instance class method, or a global/namespaced function. Non-fatal error types include `E_USER_ERROR` and `E_RECOVERABLE_ERROR`.

Fatal (non-recoverable) Errors will raise an `E2EX\FatalErrorException`. These can only be handled inside your registered exception handler. Fatal error types include `E_ERROR`, `E_PARSE` and `E_COMPILE_ERROR`.

Both of the Exception types extend PHPs native [\\ErrorException](http://php.net/manual/en/class.errorexception.php).

PSR-3 Logging
-------------

[](#psr-3-logging)

To enable [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) logging, all that's required is to pass in a PSR-3 compatible logger instance:

```
E2EX\Converter::seLogger($logger);
```

- `E_NOTICE`, `E_USER_NOTICE` and `E_STRICT` will be logged at the `notice` level.
- `E_WARNING`, `E_CORE_WARNING`, `E_DEPRECATED`, `E_USER_DEPRECATED` , `E_COMPILE_WARNING` and `E_USER_WARNING` will be logged at the `warning` level.
- `E_USER_ERROR` and `E_RECOVERABLE_ERROR` will be logged at the `error` level.
- `E_ERROR`, `E_COMPILE_ERROR` and `E_PARSE` will be logged at the `critical` level.

If you only want to log Notices and Warnings, pass in boolean `false` as the second argument when you register the handler.

```
E2EX\Converter::register(E_ALL, false); // ErrorExceptions and FatalErrorExceptions will not be passed to the Logger
```

A context array will be added to each log entry containing the PHP error type (as an integer), the filename, the line number and (optionally) the stack trace as an indexed array of associative arrays. By default, the stack trace will be limited to a depth of 5. You can vary this by passing a 3rd paramater to the `register()` method, like so:

```
E2EX\Converter::register(E_ALL, true, 10);
```

If you don't want to log stack traces, simply pass in 0 as the 3rd argument.

Note that once PSR-3 logging has been enabled, non-fatal Errors, Notices and Warnings set to be handled by E2EX will not be handled by PHP's built in error handler, and so will not be logged to PHP's error\_log.

Caveats
-------

[](#caveats)

- Fatal startup errors (`E_CORE_ERROR`) will not be handled.
- If more than one startup warning (`E_CORE_WARNING` and/or `E_DEPRECATED`) occurs, only the last one will be passed to the logger.
- `E_ERROR`, `E_COMPILE_ERROR` and `E_PARSE` errors will not be converted to Exceptions if they occur in the same file as the handler is registered in.
- `E_ERROR`, `E_PARSE`, `E_CORE_ERROR`, `E_CORE_WARNING`, `E_COMPILE_ERROR`, `E_COMPILE_WARNING`, and most of `E_STRICT` will not be passed to the logger if raised in the same file the handler is registered in. They will however be logged with PHP's built-in error handler if error\_log is set in php.ini.

Running the Tests
-----------------

[](#running-the-tests)

[Install dev dependencies](http://getcomposer.org/doc/04-schema.md#require-dev) (if not already installed).

Run tests:

```
$ phpunit tests

```

Requirements
------------

[](#requirements)

- php &gt;= 5.3.6

License
-------

[](#license)

MIT

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

4857d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3254435?v=4)[Freddie Frantzen](/maintainers/freddiefrantzen)[@freddiefrantzen](https://github.com/freddiefrantzen)

---

Top Contributors

[![freddiefrantzen](https://avatars.githubusercontent.com/u/3254435?v=4)](https://github.com/freddiefrantzen "freddiefrantzen (10 commits)")

---

Tags

logphploggingexceptionerrorerror-handlererrorexception

### Embed Badge

![Health badge](/badges/e2ex-e2ex/health.svg)

```
[![Health](https://phpackages.com/badges/e2ex-e2ex/health.svg)](https://phpackages.com/packages/e2ex-e2ex)
```

###  Alternatives

[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1861.6M3](/packages/justbetter-magento2-sentry)[phptek/sentry

Sentry.io integration for SilverStripe. Binds Sentry.io to SilverStripe's error &amp; exception handling subsystem.

15208.0k4](/packages/phptek-sentry)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
