PHPackages                             tekord/php-result - 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. [Debugging &amp; Profiling](/categories/debugging)
4. /
5. tekord/php-result

ActiveLibrary[Debugging &amp; Profiling](/categories/debugging)

tekord/php-result
=================

Result object for PHP inspired by the Rust programming language

v0.9(1y ago)414.3k↓35.8%MITPHPPHP &gt;=8.0

Since Aug 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/tekord/php-result)[ Packagist](https://packagist.org/packages/tekord/php-result)[ Docs](https://github.com/tekord/php-result)[ RSS](/packages/tekord-php-result/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (15)Used By (0)

PHP Result
==========

[](#php-result)

Result object for PHP inspired by the Rust programming language.

This object is useful when you want your errors to be returned instead of being thrown. Several helper functions make it easy to use.

[![PHP Version Support](https://camo.githubusercontent.com/b0a83316cb93ddc018a32a585eab9673823e9136bd022c3b722880a90947ebbc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f74656b6f72642f7068702d726573756c743f6c6f676f3d70687026636f6c6f723d383839324246)](https://www.php.net/supported-versions.php)[![Packagist version](https://camo.githubusercontent.com/6901d1e3d39e9d9258424cb4e75fa0972c65565362e9647e38ad06c8de290e83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74656b6f72642f7068702d726573756c742e7376673f6c6f676f3d7061636b6167697374)](https://packagist.org/packages/tekord/php-result)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](https://github.com/tekord/php-result/blob/main/LICENSE-MIT)

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

[](#installation)

Install the package via Composer:

```
composer require tekord/php-result
```

Usage
-----

[](#usage)

Example:

```
class ErrorInfo {
    public $code;
    public $message;
    public $context;

    public function __construct($code, $message, $context = []) {
        $this->code = $code;
        $this->message = $message;
        $this->context = $context;
    }
}

function createOrder(User $user, $products): Result {
    if (!$user->isVerified())
        return Result::fail(
            new ErrorInfo("unverified_user", "Unverified users are not allowed to order", [
                'user' => $user
            ])
        );

    if ($user->hasDebts())
        return Result::fail(
            new ErrorInfo("user_has_debts", "Users with debts are not allowed to order new items", [
                'user' => $user
            ])
        );

    if ($products->isEmpty())
        return Result::fail(
            new ErrorInfo("no_products", "Products cannot be empty")
        );

    // Create a new order here...

    return Result::success($newOrder);
}

// ...

$createOrderResult = createOrder($user, $productsFromCart);

// This will throw a panic exception if the result contains an error
$newOrder = $createOrderResult->unwrap();

// - OR -

// You can check if the result is OK and make a decision on it
if ($createOrderResult->isOk()) {
    $newOrder = $createOrderResult->ok;

    // ...
}
else {
    throw new DomainException($createOrderResult->error->message);
}

// - OR -

// Get a default value if the result contains an error
$newOrder = $createOrderResult->unwrapOrDefault(new Order());
```

You can extend the Result class to override the exception class (note the phpDoc):

```
/**
 * @tempate OkType
 * @tempate ErrorType
 *
 * @extends Result
 */
class CustomResult extends Result {
    static $panicExceptionClass = DomainException::class;
}
```

Testing
-------

[](#testing)

```
composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity30

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Recently: every ~145 days

Total

11

Last Release

718d ago

PHP version history (2 changes)0.5.0PHP ^7.4|^8.0

v0.9-alphaPHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0f3c0971c1772194004645045af84bba7059bff710578b4a29c97d850c51cbdf?d=identicon)[tekord](/maintainers/tekord)

---

Top Contributors

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

---

Tags

error-handlingphpresultresult-typerustrust-langphpwrapperresulterror handlingdata structures

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tekord-php-result/health.svg)

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

###  Alternatives

[laracraft-tech/laravel-xhprof

Easy XHProf setup to profile your laravel application!

235321.4k](/packages/laracraft-tech-laravel-xhprof)[bavix/laravel-xhprof

Quick profiling of your code for Laravel

22156.6k](/packages/bavix-laravel-xhprof)[h4cc/phpqatools

A meta composer package for PHP QA Tools.

6418.6k1](/packages/h4cc-phpqatools)[thehocinesaad/laravel-error-ai

This package adds Ask AI button to the error page.

2214.4k](/packages/thehocinesaad-laravel-error-ai)

PHPackages © 2026

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