PHPackages                             pldin601/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. pldin601/php-result

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pldin601/php-result
===================

Abstraction that represends ok/fail result primitives

v1.1(9y ago)247MIT

Since Jun 1Compare

[ Source](https://github.com/pldin601/php-result)[ Packagist](https://packagist.org/packages/pldin601/php-result)[ RSS](/packages/pldin601-php-result/feed)WikiDiscussions Synced yesterday

READMEChangelog (3)Dependencies (3)Versions (7)Used By (0)

php-result
==========

[](#php-result)

[![Build Status](https://camo.githubusercontent.com/a9005f46cc5be5c599fc7899cc860fa70f42e605812d7d67b2c48a398b0d88d5/68747470733a2f2f7472617669732d63692e6f72672f706c64696e3630312f7068702d726573756c742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pldin601/php-result)[![Code Climate](https://camo.githubusercontent.com/bdb6df6e3ad7d59477fe7a638455c674a4ca37e8e217a173c475d41745ce7161/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f706c64696e3630312f7068702d726573756c742f6261646765732f6770612e737667)](https://codeclimate.com/github/pldin601/php-result)[![Test Coverage](https://camo.githubusercontent.com/ce4c9eaa493614dab58db86ac9cd2b0deb161e557df3e998db8e5dde17d11215/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f706c64696e3630312f7068702d726573756c742f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/pldin601/php-result/coverage)[![Issue Count](https://camo.githubusercontent.com/91064347fd57a4045bd0f29bd7321b04f997f32a237208f01cd5de6c37135f80/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f706c64696e3630312f7068702d726573756c742f6261646765732f69737375655f636f756e742e737667)](https://codeclimate.com/github/pldin601/php-result)

Result is an abstraction that can be used for returning and propagating errors. Result can be `ok`, representing success and containing a value, or `fail`, representing error and containing an error value.

Inspired by Rust's module `std::result`.

Functions
---------

[](#functions)

```
use Result as R;

R\ok('foo');
R\fail($value);

R\resultify($callable, ...$args);
R\notNull($callable, ...$args);
R\tryCatch($callable, $exceptionTransformCallable, ...$args);

R\isOk($result);
R\isFail($result);

R\ifOk($result, $callable);
R\ifFail($result, $callable);

R\getOrThrow($result, $exceptionClass);

R\bind($result, $callable);
R\pipeline(...$callables);
```

Pipeline example
----------------

[](#pipeline-example)

```
use Result as R;

$readFile = function($filename) {
    return R\with($filename, 'file_exists', 'file_get_contents', function () {
        return "Can't read the file.";
    });
}

$proceedFile = function($content) {
    $transform = function ($exception) {
        return $exception->getMessage();
    };

    return R\tryCatch('doSomethingWithContent', $transform, $content);
}

$saveFile = function($filename) {
    return function ($content) use ($filename) {
        $bytesWritten = file_put_contents($filename, $content);

        return $bytesWritten === false
            ? R\fail("Can't save the file!")
            : R\ok();
    }
}

$pipeline = R\pipeline($readFile, $proceedFile, $saveFile('/tmp/output_file'));

$result = $pipeline('/tmp/input_file');

R\ifOk($result, function () {
    echo 'File successfully saved.';
});
```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Total

4

Last Release

3638d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6b15606ac61bb3a0a0c37f0634e950a5168f617fac716edc2eb83392a14b2e89?d=identicon)[pldin601](/maintainers/pldin601)

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

PHPackages © 2026

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