PHPackages                             texthtml/result-option - 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. texthtml/result-option

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

texthtml/result-option
======================

Result and Option type for your functions returned values.

03[6 issues](https://github.com/texthtml/php-result-option/issues)[5 PRs](https://github.com/texthtml/php-result-option/pulls)PHP

Since Sep 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/texthtml/php-result-option)[ Packagist](https://packagist.org/packages/texthtml/result-option)[ RSS](/packages/texthtml-result-option/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (6)Used By (0)

texthtml/result-option
======================

[](#texthtmlresult-option)

Result and Option type for your functions returned values.

Result&lt;T,E&gt; is the type used for returning and propagating errors. It is either an Ok(T), representing success and containing a value, er an Error(E), representing error and containing an error value.

Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. Option types have a number of uses:

- Initial values
- Return values for functions that are not defined over their entire input range (partial functions)
- Return value for otherwise reporting simple errors, where None is returned on error
- Optional class properties
- Optional function arguments
- Nullable values

Option is the type used for a value either containing a T or nothing.

Result Usage
------------

[](#result-usage)

[Full API documentation](docs/)

### Declaring and writing a function returning a Result

[](#declaring-and-writing-a-function-returning-a-result)

```
/**
 * @return Result
 */
function readFile(string $path): Result
{
    return match ($content = file_get_contents($path)) {
        false => Result::error("file at $path could not be read"),
        default => Result::ok($content),
    };
}
```

### Using a Result

[](#using-a-result)

Checking if the result is an error or not:

```
$content = readFile("/path/to/file");

if ($content->isError()) die("{$content->unwrapError()}" . PHP_EOL);

echo $content->unwrap();
```

Working on the result:

```
/**
 * @param Result
 * @return Result
 */
function length(Result $o): Result
{
    return $o->map("strlen");
}
```

Option Usage
------------

[](#option-usage)

### Declaring and writing a function returning an Option

[](#declaring-and-writing-a-function-returning-an-option)

```
/**
 * @return Option
 */
function firstChar(string $s): Option
{
    return match (true) {
        $s === "" => Option::none(),
        default   => Option::value($s[0]),
    };
}
```

### Using an Option value

[](#using-an-option-value)

Checking if the result is an error or not:

```
$c = firstChar("Option");

if ($c->isNone()) die("There is no first character in the string" . PHP_EOL);

echo "firstChar(\"Option\") = {$c->unwrap()}", PHP_EOL;
```

Working on the result:

```
/**
 * @param Option
 * @return Option
 */
function even(Option $o): Option
{
    return $o->map((int $i) => $i % 2 === 0);
}
```

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor1

Top contributor holds 87.5% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3943b5c35797d1ede53aaed3d6812e4cf5b2dba7619a00dc7a381480a7b3d330?d=identicon)[mathroc](/maintainers/mathroc)

---

Top Contributors

[![mathroc](https://avatars.githubusercontent.com/u/291531?v=4)](https://github.com/mathroc "mathroc (7 commits)")[![text-html-renovate[bot]](https://avatars.githubusercontent.com/u/6465918?v=4)](https://github.com/text-html-renovate[bot] "text-html-renovate[bot] (1 commits)")

---

Tags

libphpstd

### Embed Badge

![Health badge](/badges/texthtml-result-option/health.svg)

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

###  Alternatives

[kevinchappell/form-builder

jQuery formBuilder

2.7k6.9k2](/packages/kevinchappell-form-builder)

PHPackages © 2026

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