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

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

ghostwriter/option
==================

Provides an Option type implementation for PHP

2.0.0(1y ago)34.5M—8.1%5BSD-3-ClausePHPPHP &gt;=8.4CI passing

Since May 19Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/ghostwriter/option)[ Packagist](https://packagist.org/packages/ghostwriter/option)[ Docs](https://github.com/ghostwriter/option)[ GitHub Sponsors](https://github.com/sponsors/ghostwriter)[ RSS](/packages/ghostwriter-option/feed)WikiDiscussions 2.0.x Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (23)Used By (5)

Option
======

[](#option)

[![GitHub Sponsors](https://camo.githubusercontent.com/4fe51cf5414ce900106c9115fb17bb4043b13b641ee599a6f3a5a3a65da8345a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73706f6e736f72732f67686f73747772697465723f6c6162656c3d53706f6e736f722b4067686f73747772697465722f6f7074696f6e266c6f676f3d4769744875622b53706f6e736f7273)](https://github.com/sponsors/ghostwriter)[![Automation](https://github.com/ghostwriter/option/actions/workflows/automation.yml/badge.svg)](https://github.com/ghostwriter/option/actions/workflows/automation.yml)[![Supported PHP Version](https://camo.githubusercontent.com/af007caa09a39e9f6f3363f2caf9e6b27ce8538caa0c78d105f70edc4ce5bae5/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f7068702f67686f73747772697465722f6f7074696f6e3f636f6c6f723d383839326266)](https://www.php.net/supported-versions)[![Downloads](https://camo.githubusercontent.com/99e64b538cbf3750b31dc985aefec44874eb59d4a9f34c8d1efc382f4d9e3a62/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f64742f67686f73747772697465722f6f7074696f6e3f636f6c6f723d626c7565)](https://packagist.org/packages/ghostwriter/option)

Provides an **`Option`** type implementation for PHP.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ghostwriter/option
```

### Star ⭐️ this repo if you find it useful

[](#star-️-this-repo-if-you-find-it-useful)

You can also star (🌟) this repo to find it easier later.

Usage
-----

[](#usage)

```
use Ghostwriter\Option\Exception\NullPointerException;
use Ghostwriter\Option\None;
use Ghostwriter\Option\Some;
use Ghostwriter\Option\Option;

$message = '#BlackLivesMatter';
Option::new($message); // return `Some`

$some = Some::new($message); // return `Some`
echo $some->get(); // prints #BlackLivesMatter

$none = None::new(); // return `None`

// calling the `get` method on `None` will throw `NullPointerException`
echo $none->get(); // throw `NullPointerException`

echo $none->getOr('#BLM'); // prints #BLM

// calling the `new` static method with `null` will return `None`
Option::new(null); // return `None`

// calling the `new` static method with `null will throw `NullPointerException`
Some::new(null); // throws `NullPointerException`

// calling the `new` static method with `None will throw `NullPointerException`
Some::new(None::new()); // throws `NullPointerException`

--- Example

function divide(int $x, int $y): OptionInterface
{
    if ($y === 0) {
        return None::new();
    }

    return Some::new($x / $y);
}

divide(1, 0); // None
divide(1, 1); // Some(1)
```

Testing
-------

[](#testing)

```
composer test
```

### Credits

[](#credits)

- [Nathanael Esayeas](https://github.com/ghostwriter)
- [All Contributors](https://github.com/ghostwriter/option/contributors)

### Changelog

[](#changelog)

Please see [CHANGELOG.md](./CHANGELOG.md) for more information on what has changed recently.

### License

[](#license)

Please see [LICENSE](./LICENSE) for more information on the license that applies to this project.

### Security

[](#security)

Please see [SECURITY.md](./SECURITY.md) for more information on security disclosure process.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance69

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 99.9% 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 ~88 days

Recently: every ~248 days

Total

17

Last Release

54d ago

Major Versions

0.3.0 → 1.0.02022-09-29

1.5.x-dev → 2.0.02025-02-06

2.1.x-dev → 3.0.x-dev2026-03-25

PHP version history (8 changes)0.1.0PHP &gt;=8.0, &lt;8.2

0.2.0PHP &gt;=8.0,&lt;8.2

1.0.1PHP &gt;=8.0,&lt;8.3

1.3.0PHP &gt;=8.1,&lt;8.3

1.5.0PHP &gt;=8.1 &lt;8.3

1.5.1PHP &gt;=8.1,&lt;8.4

2.0.0PHP &gt;=8.4

2.0.x-devPHP ~8.4.0 || ~8.5.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/1dbb0131801cc451dad9917ab29aa823b25d7eebc9f3875a9d481d109bdb44ee?d=identicon)[ghostwriter](/maintainers/ghostwriter)

---

Top Contributors

[![ghostwriter](https://avatars.githubusercontent.com/u/9754361?v=4)](https://github.com/ghostwriter "ghostwriter (1399 commits)")[![sanmai](https://avatars.githubusercontent.com/u/139488?v=4)](https://github.com/sanmai "sanmai (1 commits)")

---

Tags

ghostwritermaybeoptionoption-typephpoptionghostwriter

### Embed Badge

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

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

###  Alternatives

[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[kartik-v/dependent-dropdown

A multi level dependent dropdown JQuery plugin that allows nested dependencies.

1805.0M3](/packages/kartik-v-dependent-dropdown)[fof/nightmode

Add a Night Mode option for your users to use on your Flarum forum

3774.5k2](/packages/fof-nightmode)[chippyash/monad

Functional programming Monad support

2828.1k8](/packages/chippyash-monad)

PHPackages © 2026

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