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

ActiveLibrary

aharisu/option
==============

PHP Option object like a Rust language

1.3.0(2y ago)2748Apache-2.0PHPPHP ^7.0|^8.0

Since Mar 9Pushed 2y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

PHP Option object like a [Rust Option type](https://doc.rust-lang.org/std/option/enum.Option.html).
===================================================================================================

[](#php-option-object-like-a-rust-option-type)

[![Software License](https://camo.githubusercontent.com/f9a2da5664498a2a168a000b85719b4e5a61b6df8aae02cca978ef2580f8b1dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d417061636865253230322e302d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE-APACHE)[![Software License](https://camo.githubusercontent.com/39388f8c2ce4a21e0d16b754142eada2846f25de0cc6ef58326010c3f55d287d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d4954322d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE-MIT2)[![Build Status](https://github.com/aharisu/php-option/actions/workflows/tests.yml/badge.svg)](https://github.com/aharisu/php-option/actions)[![Coverage Status](https://camo.githubusercontent.com/2ea25c89b7c6d8a1e961705c0160bbe2790505ea2d7dddceff0be9f6ce82ff9f/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f616861726973752f7068702d6f7074696f6e2f62616467652e737667)](https://coveralls.io/github/aharisu/php-option)[![Latest Version](https://camo.githubusercontent.com/b93a07c6f8312cc5338525dfc4a307a7a345d2d93a8ef042e290563858d18a46/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f616861726973752f7068702d6f7074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/aharisu/php-option/releases)

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

[](#version-information)

It will work with both PHP 7.x and PHP 8.x.
Tested with the following PHP versions

- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2

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

[](#installation)

```
composer require aharisu/option
```

Usage
-----

[](#usage)

```
// make some object
$some = some(1);

// make none object
$none = none();

if ($some->isSome()) {
    $v = $some->unwrap();
}
if ($none->isNone()) {
    //do something
}

if (null != $v = $some->tryUnwrap()) {
    //do something
    print_r($v);
}

$some->someThen(function ($v) {
    //do something
    print_r($v);
});

$v2 = $none->unwrapOr(2);
$k = 10;
$v3 = $none->unwrapOrElse(fn () => 2 * $k);

// true
if (some(1)->equals(1)) {
}
if (some(1)->equals(some(1))) {
}
// false
if (none()->equals(null)) {
}

// false and type mismatch warning
if (some(1)->equals(1.0)) {
}
// false and type mismatch warning
if (some(1)->equals('1')) {
}
```

Using class property
--------------------

[](#using-class-property)

```
use aharisu\Option;

class ValueType
{
    /**
     * @param Option $text
     * @param Option    $value
     */
    public function __construct(
        public readonly int $id,
        public readonly Option $text,
        public readonly Option $value,
    ) {
    }
}

new ValueType(
    1,
    toOption('text'), //some
    toOption(null),   //none
);
```

License
-------

[](#license)

Apache 2.0 &amp; MIT

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~42 days

Total

4

Last Release

1038d ago

PHP version history (3 changes)1.0.0PHP ^7.3|^8.0

1.1.0PHP ^8.0

1.2.0PHP ^7.0|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/824a5fa37c59a7d129bb6362f60de2530e90d2efac52fa83bfeb69c7d3c130e0?d=identicon)[aharisu](/maintainers/aharisu)

---

Top Contributors

[![aharisu](https://avatars.githubusercontent.com/u/441579?v=4)](https://github.com/aharisu "aharisu (42 commits)")

---

Tags

optionphptypephptypeoptionnull

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[phpoption/phpoption

Option Type for PHP

2.7k541.2M159](/packages/phpoption-phpoption)[zakirullin/mess

Convenient array-related routine &amp; better type casting

21228.9k2](/packages/zakirullin-mess)[strictus/strictus

Strict Typing for local variables in PHP

1606.9k](/packages/strictus-strictus)[webparking/laravel-type-safe-collection

This package provides type-safe extension of the laravel collection, forcing a single type of object.

378.2k](/packages/webparking-laravel-type-safe-collection)

PHPackages © 2026

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