PHPackages                             jefvda/php-result-monad - 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. jefvda/php-result-monad

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

jefvda/php-result-monad
=======================

A 'Result' monad type for php

1.0.2(2y ago)08[2 issues](https://github.com/JefvdA/php-result-monad/issues)MITPHP

Since Nov 13Pushed 2y ago1 watchersCompare

[ Source](https://github.com/JefvdA/php-result-monad)[ Packagist](https://packagist.org/packages/jefvda/php-result-monad)[ RSS](/packages/jefvda-php-result-monad/feed)WikiDiscussions main Synced 2d ago

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

PHP Result Monad Library
========================

[](#php-result-monad-library)

Overview
--------

[](#overview)

The PHP Result Monad library provides a simple and effective way to handle the results of actions, offering an alternative approach to exception handling without the need for throwing exceptions. The core component of this library is the `Result` class, which encapsulates the outcome of an action and can be created from either a successful value or an exception.

🔗 Installation
--------------

[](#-installation)

You can install this package via Composer:

```
composer require jefvda/php-result-monad
```

Result Class
------------

[](#result-class)

### Factory Methods

[](#factory-methods)

#### createFromValue

[](#createfromvalue)

```
/**
 * @param mixed $value The value associated with the result.
 * @return Result The successful Result which includes the value.
 */
public static function createFromValue(mixed $value): self
```

-&gt; Creates a successful `Result` instance with the provided value.

#### createFromException

[](#createfromexception)

```
/**
 * @param Exception $exception The exception that explains why the result was not successful.
 * @return Result The not successful Result that includes the exception.
 */
public static function createFromException(Exception $exception): self
```

-&gt; Creates a not successful `Result` instance with the provided exception.

### Public Methods

[](#public-methods)

#### Getters

[](#getters)

- `getValue` -&gt; Returns the value associated with the result.
- `getException` -&gt; Returns the exception associated with the result
- `isSuccess` -&gt; Returns a boolean indicating whether the action was successful.

#### match

[](#match)

```
/**
 * @param callable $valueCallback The callback for successful results.
 * @param callable $exceptionCallback The callback for unsuccessful results.
 * @return mixed The return value of the callback that has been called.
 */
public function match(callable $valueCallback, callable $exceptionCallback): mixed
```

-&gt; Allows matching on the result, executing the appropriate callback based on success or failure.

### Usage

[](#usage)

Here's a brief example demonstrating the basic usage of the `Result` class:

```
// Create a successful result with a value
$successResult = Result::createFromValue('Hello, Result!');

// Create an unsuccessful result with an exception
$exception = new \Exception('Something went wrong.');
$failureResult = Result::createFromException($exception);

// Match on the results
$successMessage = $successResult->match(
    fn ($value) => 'Success: ' . $value,
    fn ($exception) => 'Failure: ' . $exception,
);

$failureMessage = $failureResult->match(
    fn ($value) => 'Success: ' . $value,
    fn ($exception) => 'Failure: ' . $exception,
);

echo $successMessage; // Will display 'Success: Hello, Result!' -> as the `Result` was successful
echo $failureMessage; // Will display 'Failure: Something went wrong.' -> as the `Result` was not successful
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.2% 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 ~9 days

Total

3

Last Release

946d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c515c08ee4cc72a3f80ab98cc5ab08946774cc48a8677a881bc99ebfeff480f?d=identicon)[JefvdA](/maintainers/JefvdA)

---

Top Contributors

[![JefvdA](https://avatars.githubusercontent.com/u/13435783?v=4)](https://github.com/JefvdA "JefvdA (25 commits)")[![antonowano](https://avatars.githubusercontent.com/u/8445829?v=4)](https://github.com/antonowano "antonowano (1 commits)")

---

Tags

monadphpphp-library

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[saumini/count

A Laravel Nova field.

30548.4k1](/packages/saumini-count)[xttribute/xttribute

XML to DTO, nicely!

6130.0k](/packages/xttribute-xttribute)[nejcc/php-datatypes

PHP Data types

812.5k1](/packages/nejcc-php-datatypes)

PHPackages © 2026

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