PHPackages                             timefrontiers/php-instance-error - 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. timefrontiers/php-instance-error

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

timefrontiers/php-instance-error
================================

PHP Instance Error handler with access-based filtering

v1.0.0(1mo ago)0214MITPHPPHP &gt;=8.1

Since Apr 16Pushed 1mo agoCompare

[ Source](https://github.com/timefrontiers/php-instance-error)[ Packagist](https://packagist.org/packages/timefrontiers/php-instance-error)[ Docs](https://github.com/timefrontiers/php-instance-error)[ RSS](/packages/timefrontiers-php-instance-error/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (4)

TimeFrontiers PHP Instance Error
================================

[](#timefrontiers-php-instance-error)

Extract and filter errors from objects based on user access rank.

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

[](#installation)

```
composer require timefrontiers/php-instance-error
```

Overview
--------

[](#overview)

`InstanceError` extracts errors from any object that has:

- A `getErrors()` method (recommended, used by `HasErrors` trait), or
- A public `$errors` property (legacy)

Errors are filtered based on the user's access rank, so sensitive system errors only appear to developers/admins.

Error Format
------------

[](#error-format)

Errors must follow this format:

```
[min_rank, code, message, file, line]
// Example:
[0, 256, 'Invalid email format', '/app/User.php', 42]
```

Where `min_rank` is the minimum `AccessRank` value required to see this error.

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use TimeFrontiers\InstanceError;

// Extract errors visible to current user (uses global $session)
$extractor = new InstanceError($userObject);
$errors = $extractor->get();

// Get errors for a specific context
$loginErrors = $extractor->get('login');

// Get only error messages (strings)
$messages = $extractor->get('login', true);
```

### Override Rank

[](#override-rank)

```
use TimeFrontiers\InstanceError;
use TimeFrontiers\AccessRank;

// Show ALL errors regardless of rank
$extractor = new InstanceError($object, true);

// Show errors visible to DEVELOPER rank
$extractor = new InstanceError($object, AccessRank::DEVELOPER);

// Show errors visible to rank 5
$extractor = new InstanceError($object, 5);
```

### Helper Methods

[](#helper-methods)

```
$extractor = new InstanceError($object);

// Check if errors exist
if ($extractor->has('validation')) {
  // ...
}

// Count visible errors
$count = $extractor->count();
$validationCount = $extractor->count('validation');

// Get first error message
$first = $extractor->first();

// Get all messages as flat array
$allMessages = $extractor->messages();
```

### Logging Errors

[](#logging-errors)

If `timefrontiers/php-error-log` is installed:

```
$extractor = new InstanceError($object, true);

// Log all errors
$extractor->log();

// Log specific context
$extractor->log('database');

// Log to specific file
$extractor->log('database', '/var/log/app/db-errors.log');
```

### Adding Errors

[](#adding-errors)

```
$extractor = new InstanceError($object);

// Add an error to the collection
$extractor->put('custom', [
  AccessRank::GUEST->value,  // min_rank
  400,                        // code
  'Something went wrong',     // message
  __FILE__,                   // file
  __LINE__                    // line
]);
```

Rank Resolution
---------------

[](#rank-resolution)

When no override is provided, rank is resolved in this order:

1. Global `$session->access_rank` property
2. Global `$session->access_rank()` method
3. Default: `AccessRank::GUEST` (0)

Integration with HasErrors Trait
--------------------------------

[](#integration-with-haserrors-trait)

Objects using the `HasErrors` trait work seamlessly:

```
use TimeFrontiers\Helper\HasErrors;

class MyService {
  use HasErrors;

  public function process():bool {
    if ($error) {
      $this->_userError('process', 400, 'Processing failed');
      return false;
    }
    return true;
  }
}

// Extract errors
$service = new MyService();
$service->process();

$extractor = new InstanceError($service);
$errors = $extractor->get('process');
```

Access Rank Levels
------------------

[](#access-rank-levels)

RankValueTypical UseGUEST0Validation, user-facing errorsUSER1Basic user errorsMODERATOR4Business logic errorsDEVELOPER7SQL, connection errorsSUPERADMIN8Sensitive debug infoDependencies
------------

[](#dependencies)

- `timefrontiers/php-core` - For `AccessRank` enum
- `timefrontiers/php-has-errors` - For error handling trait

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance89

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfcd9a5645cb2deb0771b9102be193d63b495564b1e06c0b85cb31bf028d0887?d=identicon)[ikechukwuokalia](/maintainers/ikechukwuokalia)

---

Top Contributors

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

---

Tags

phperrorfilteringaccess-controlinstance

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/timefrontiers-php-instance-error/health.svg)

```
[![Health](https://phpackages.com/badges/timefrontiers-php-instance-error/health.svg)](https://phpackages.com/packages/timefrontiers-php-instance-error)
```

###  Alternatives

[justbetter/magento2-sentry

Magento 2 Logger for Sentry

1851.5M3](/packages/justbetter-magento2-sentry)[codex-team/hawk.php

PHP errors Catcher module for Hawk.so

2233.2k2](/packages/codex-team-hawkphp)[e2ex/e2ex

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

101.5k](/packages/e2ex-e2ex)

PHPackages © 2026

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