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

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

prewk/option
============

Option object for PHP inspired by Rust

4.1.0(9mo ago)47861.7k—4.8%10[7 PRs](https://github.com/prewk/option/pulls)2(MIT or Apache-2.0)PHPPHP &gt;=8.1.0CI failing

Since Apr 28Pushed 9mo ago3 watchersCompare

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

READMEChangelogDependencies (7)Versions (32)Used By (2)

PHP Option Object [![Build Status](https://github.com/prewk/option/actions/workflows/test.yml/badge.svg)](https://github.com/prewk/option/actions) [![Coverage Status](https://camo.githubusercontent.com/de442700a70609f43b51b9446d9b1b413d6556d6ce4b2aee1e1928851120dfb3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f707265776b2f6f7074696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/prewk/option?branch=master)
=================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-option-object--)

A PHP implementation of [Rust's Option type](https://doc.rust-lang.org/std/option/enum.Option.html) with roughly the same API.

Version information
-------------------

[](#version-information)

Version 4.x.x requires PHP 8.1+. Make sure you match the versions for this and the [Result](https://github.com/prewk/result) library if you use both.

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

[](#installation)

```
composer require prewk/option
```

Usage
-----

[](#usage)

```
use Prewk\Option;
use Prewk\Option\{Some, None};

function findSomething(): Option {
    // ...
    if ($foundSomething) {
        return new Some($thing);
    } else {
        return new None;
    }
}

function findSomethingElse(): Result {
    // ...
    if ($foundSomething) {
        return new Some($thing);
    } else {
        return new None;
    }
}

// Fallback to value
$value = findSomething()->unwrapOr(null);

// Fallback to option and throw an exception if both fail
$value = findSomething()->or(findSomethingElse())->unwrap();

// Throw custom exception on missing thing (None)
$value = findSomething()->expect(new Exception("Oh noes!"));

```

License
-------

[](#license)

MIT &amp; Apache 2.0

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance58

Moderate activity, may be stable

Popularity51

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity83

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 70.7% 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 ~132 days

Recently: every ~164 days

Total

24

Last Release

276d ago

Major Versions

0.0.5 → 1.0.02017-07-31

1.3.0 → 2.0.02018-03-19

2.1.1 → 3.0.02021-03-24

3.3.0 → 4.0.02024-05-08

PHP version history (3 changes)1.0.0PHP &gt;=7.0

3.0.0PHP &gt;=7.3.0

4.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/640102?v=4)[Oskar Thornblad](/maintainers/prewk)[@prewk](https://github.com/prewk)

---

Top Contributors

[![prewk](https://avatars.githubusercontent.com/u/640102?v=4)](https://github.com/prewk "prewk (29 commits)")[![Lctrs](https://avatars.githubusercontent.com/u/5477973?v=4)](https://github.com/Lctrs "Lctrs (7 commits)")[![andrew-demb](https://avatars.githubusercontent.com/u/12499813?v=4)](https://github.com/andrew-demb "andrew-demb (2 commits)")[![adrianpanicek](https://avatars.githubusercontent.com/u/693432?v=4)](https://github.com/adrianpanicek "adrianpanicek (1 commits)")[![thgs](https://avatars.githubusercontent.com/u/8940963?v=4)](https://github.com/thgs "thgs (1 commits)")[![tminich](https://avatars.githubusercontent.com/u/51162280?v=4)](https://github.com/tminich "tminich (1 commits)")

---

Tags

datastructuresphprust

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[fidry/cpu-core-counter

Tiny utility to get the number of CPU cores.

238148.2M23](/packages/fidry-cpu-core-counter)[kiboit/phast

A toolbox for optimizing web page performance

3615.4k1](/packages/kiboit-phast)[mozammil/putio-php

PHP SDK for put.io

101.1k](/packages/mozammil-putio-php)

PHPackages © 2026

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