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)1911.2k↑56.9%3[1 issues](https://github.com/texthtml/maybe/issues)[3 PRs](https://github.com/texthtml/maybe/pulls)MITPHPPHP ^8.1CI passing

Since Jul 18Pushed 3w ago3 watchersCompare

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

READMEChangelog (8)Dependencies (13)Versions (16)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

48

—

FairBetter than 93% of packages

Maintenance72

Regular maintenance activity

Popularity36

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

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

###  Release Activity

Cadence

Every ~145 days

Recently: every ~163 days

Total

8

Last Release

429d 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] (24 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

[rmunate/php2js

Effortlessly share PHP Laravel values with external JavaScript files using just one command, thanks to the seamless integration of PHP2JS.

2058.3k](/packages/rmunate-php2js)

PHPackages © 2026

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