PHPackages                             debuss-a/problem-details - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. debuss-a/problem-details

ActiveLibrary[HTTP &amp; Networking](/categories/http)

debuss-a/problem-details
========================

An implementation of RFC 7807 - Problem Details for HTTP APIs

1.0.2(9mo ago)01284MITPHPPHP ^8.2CI failing

Since Jul 1Pushed 8mo agoCompare

[ Source](https://github.com/debuss/problem-details)[ Packagist](https://packagist.org/packages/debuss-a/problem-details)[ RSS](/packages/debuss-a-problem-details/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (4)

Problem Details
===============

[](#problem-details)

An implementation of [RFC 7807](https://tools.ietf.org/html/rfc7807) - Problem Details for HTTP APIs.

This package provides a simple way to return standardized error responses that are both machine-readable and human-friendly.

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

[](#installation)

```
composer require debuss-a/problem-details
```

Usage
-----

[](#usage)

### Creating a Problem Details object

[](#creating-a-problem-details-object)

```
use ProblemDetails\ProblemDetails;

$problem = new ProblemDetails(
    type: 'https://example.com/probs/out-of-credit',
    title: 'You do not have enough credit.',
    status: 403,
    detail: 'Your current balance is 30, but that costs 50.',
    instance: '/account/12345/msgs/abc',
    extensions: [
        'balance' => 30,
        'accounts' => ['/account/12345', '/account/67890']
    ]
);

// JSON serialization
$json = json_encode($problem);
```

### Using the ProblemDetailsException

[](#using-the-problemdetailsexception)

```
use ProblemDetails\ProblemDetailsException;

try {
    // Your application logic
    if ($user->balance < $item->price) {
        $problem = new ProblemDetails(
            type: 'https://example.com/probs/out-of-credit',
            title: 'You do not have enough credit.',
            status: 403,
            detail: "Your current balance is {$user->balance}, but that costs {$item->price}."
        );

        throw new ProblemDetailsException($problem);
    }
} catch (ProblemDetailsException $e) {
    // Deal with the exception, or...
    // ...if set, the middleware will handle this automatically
    throw $e;
}
```

### Using the Middleware

[](#using-the-middleware)

Add the middleware to your middleware pipeline:

```
use Laminas\Diactoros\ResponseFactory;
use ProblemDetails\ProblemDetailsMiddleware;

// For PSR-15 compatible frameworks
$response_factory = new ResponseFactory();
$app->add(new ProblemDetailsMiddleware($response_factory));
```

The middleware will:

1. Catch any `ProblemDetailsException`
2. Convert it to a proper Problem Details response
3. Set appropriate Content-Type header (`application/problem+json`)

About RFC 7807
--------------

[](#about-rfc-7807)

[RFC 7807](https://tools.ietf.org/html/rfc7807) defines a standard format for returning error details from HTTP APIs.
It improves error handling by providing structured data that can be easily parsed by both machines and humans.

A Problem Details object includes:

- `type` - A URI reference that identifies the problem type
- `title` - A short, human-readable summary of the problem type
- `status` - The HTTP status code
- `detail` - A human-readable explanation specific to this occurrence of the problem
- `instance` - A URI reference that identifies the specific occurrence of the problem

License
-------

[](#license)

This package is released under the MIT License. See the LICENSE file for details.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance60

Regular maintenance activity

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

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 ~18 days

Total

3

Last Release

286d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e1a70117520fe10a630d61c750bbe6888d174e9903825e741470f818ee2c5d1?d=identicon)[debuss-a](/maintainers/debuss-a)

---

Top Contributors

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

---

Tags

httppsr-7apipsr-17psr-15problem detailsrfc 7807error handling

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/debuss-a-problem-details/health.svg)

```
[![Health](https://phpackages.com/badges/debuss-a-problem-details/health.svg)](https://phpackages.com/packages/debuss-a-problem-details)
```

###  Alternatives

[laminas/laminas-stratigility

PSR-7 middleware foundation for building and dispatching middleware pipelines

586.6M81](/packages/laminas-laminas-stratigility)[middlewares/utils

Common utils for PSR-15 middleware packages

503.4M92](/packages/middlewares-utils)[wellrested/wellrested

Simple PHP Library for RESTful APIs

4818.7k4](/packages/wellrested-wellrested)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28137.8k](/packages/phpro-http-tools)[mezzio/mezzio-problem-details

Problem Details for PSR-7 HTTP APIs addressing the RFC 7807 standard

271.1M24](/packages/mezzio-mezzio-problem-details)[lcobucci/error-handling-middleware

A PSR-15 middleware compatible with RFC 7807

6171.3k1](/packages/lcobucci-error-handling-middleware)

PHPackages © 2026

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