PHPackages                             pmjones/throwable-properties - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. pmjones/throwable-properties

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

pmjones/throwable-properties
============================

Copies properties of a Throwable to a serializable object.

2.0.0(2y ago)1554.7k↓30.8%2MITPHPPHP ^8.1

Since Oct 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/pmjones/throwable-properties)[ Packagist](https://packagist.org/packages/pmjones/throwable-properties)[ Docs](http://github.com/pmjones/throwable-properties)[ RSS](/packages/pmjones-throwable-properties/feed)WikiDiscussions 2.x Synced 1mo ago

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

ThrowableProperties
===================

[](#throwableproperties)

> This package is installable via [Composer](https://getcomposer.org) as [pmjones/throwable-properties](https://packagist.org/packages/pmjones/throwable-properties).
>
> ```
> composer require pmjones/throwable-properties ^2.0
>
> ```

When using `json_encode()` with *Throwable* objects, such as *Error* and *Exception*, the result is an empty JSON object.

```
try {
    // ...
} catch (Throwable $e) {
    echo json_encode($e); // '{}'
}
```

To convert a *Throwable* into a form suitable for `json_encode()`, instantiate a new *ThrowableProperties* with it:

```
use pmjones\ThrowableProperties;

try {
    // ...
} catch (Throwable $e) {
    $t = new ThrowableProperties($e);
    echo json_encode($t); // '{"class": ... }'
}
```

*ThrowableProperties* is essentially a Data Transfer Object composed of these properties:

- `string $class`: The *Throwable* class.
- `string $message`: The *Throwable* message.
- `string $string`: A string representation of the *Throwable*.
- `int $code`: The *Throwable* code.
- `string $file`: The filename where the *Throwable* was created.
- `int $line`: The line where the *Throwable* was created.
- `array $other`: All other properties of the *Throwable* (if any).
- `array $trace`: The stack trace array, with all `'args'`elements removed.
- `?ThrowableProperties $previous`: The previously thrown exception, if any, represented as a *ThrowableProperties* instance.

*ThrowableProperties* is *Stringable* to the string form of the original *Throwable*.

```
try {
    // ...
} catch (Throwable $e) {
    $t = new ThrowableProperties($e);
    assert((string) $e === (string) $t));
}
```

If you just want the *ThrowableProperties* values, you can call `asArray()`:

```
try {
    // ...
} catch (Throwable $e) {
    $t = new ThrowableProperties($e);
    $a = $t->asArray(); // do something with the array
}
```

Finally, you can use a *ThrowableProperty* inside your own *Throwable*`jsonSerialize()` methods:

```
use pmjones\ThrowableProperties;

class MyException extends \Exception implements JsonSerializable
{
    public function jsonSerialize() : mixed
    {
        return new ThrowableProperties($this);
    }
}
```

Comparable Libraries
--------------------

[](#comparable-libraries)

Cees-Jan Kiewet has a comparable offering called [php-json-throwable](https://github.com/WyriHaximus/php-json-throwable), using functions to encode a *Throwable* instead of a standalone DTO. It works on PHP 7.4 and later, whereas this library works only on PHP 8.1 and later.

Eboreum has a related package called [eboreum/exceptional](https://github.com/eboreum/exceptional).

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

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

Total

4

Last Release

1053d ago

Major Versions

1.x-dev → 2.0.02023-06-30

PHP version history (2 changes)1.0.0PHP ^8.0

2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25754?v=4)[Paul M. Jones](/maintainers/pmjones)[@pmjones](https://github.com/pmjones)

---

Top Contributors

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

---

Tags

jsonserializeexceptionthrowableencode

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/pmjones-throwable-properties/health.svg)

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

###  Alternatives

[zumba/json-serializer

Serialize PHP variables, including objects, in JSON format. Support to unserialize it too.

129743.7k13](/packages/zumba-json-serializer)[kherge/json

Encodes, decodes, and validates JSON data.

61226.6k6](/packages/kherge-json)

PHPackages © 2026

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