PHPackages                             texthtml/maybe - 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/maybe

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

texthtml/maybe
==============

Option &amp; Result types

v0.8.0(1y ago)188.3k↑29.2%3[3 PRs](https://github.com/texthtml/maybe/pulls)MITPHPPHP ^8.1CI passing

Since Jul 18Pushed 3mo ago3 watchersCompare

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

READMEChangelog (8)Dependencies (13)Versions (15)Used By (0)

Maybe: Option &amp; Result for PHP
==================================

[](#maybe-option--result-for-php)

Help yourself by not returning `null`, `false`, `-1` or throwing exception for everything by using `Option` &amp; `Result` instead.

Using those makes it harder to make mistake, make it easy to do common operations on unknown returned values and can help static analysis tool detect incorrect logic in PHP code.

Installation
============

[](#installation)

```
composer req texthtml/maybe
```

Documentation
=============

[](#documentation)

Read the [documentation](https://doc.maybe.texthtml.net) full API description, detailed explainations and usages.

Usage
=====

[](#usage)

Option
------

[](#option)

`TH\Maybe\Option` is a type that represents an optional value: every `Option` is either `Some` and contains a value, or `None`, and does not.

```
/**
 * @return Option
 */
function divide(float $numerator, float $denominator): Option {
    return match ($denominator) {
        0.0 => Option\none(),
        default => Option\some($numerator / $denominator),
    };
}

// The return value of the function is an option
$result = divide(2.0, 3.0);

// Pattern match to retrieve the value
if ($result->isSome()) {
    // The division was valid
    echo "Result: {$result->unwrap()}";
} else {
    // The division was invalid
    echo "Cannot divide by 0";
}
```

Result
------

[](#result)

`TH\Maybe\Result` is a type that represents either success (`Ok`), containing the result of an operation or failure (`Err`), containing the reason of the failure.

```
/**
 * @return Result
 */
function parse_version(string $header): Result {
    return match ($header[0] ?? null) {
        null => Result\err("invalid header length"),
        "1" => Result\ok(1),
        "2" => Result\ok(2),
        default => Result\err("invalid version"),
    };
}

$version = parse_version("1.x");
if ($version->isOk()) {
    echo "working with version: {$version->unwrap()}";
} else {
    echo "error parsing header: {$version->unwrapErr()}";
}
// @prints working with version: 1
```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance66

Regular maintenance activity

Popularity34

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.3% 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 ~145 days

Recently: every ~163 days

Total

8

Last Release

384d ago

### 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 (45 commits)")[![text-html-renovate[bot]](https://avatars.githubusercontent.com/u/6465918?v=4)](https://github.com/text-html-renovate[bot] "text-html-renovate[bot] (22 commits)")[![kylekatarnls](https://avatars.githubusercontent.com/u/5966783?v=4)](https://github.com/kylekatarnls "kylekatarnls (2 commits)")[![MattyRad](https://avatars.githubusercontent.com/u/1143595?v=4)](https://github.com/MattyRad "MattyRad (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[spatie/color

A little library to handle color conversions

38118.9M28](/packages/spatie-color)[spatie/robots-txt

Determine if a page may be crawled from robots.txt and robots meta tags

25616.4M23](/packages/spatie-robots-txt)

PHPackages © 2026

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