PHPackages                             marvin255/optional - 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. marvin255/optional

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

marvin255/optional
==================

Optional container for PHP.

v0.2.3(3mo ago)01.5k[1 PRs](https://github.com/marvin255/optional/pulls)2MITPHPPHP &gt;=8.3CI passing

Since Jul 1Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/marvin255/optional)[ Packagist](https://packagist.org/packages/marvin255/optional)[ RSS](/packages/marvin255-optional/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (8)Versions (15)Used By (2)

Optional
========

[](#optional)

[![Latest Stable Version](https://camo.githubusercontent.com/764a2687ba25125d229dcb4a882fdf42e18dc27bc8be046d8cd089772c6453ad/68747470733a2f2f706f7365722e707567782e6f72672f6d617276696e3235352f6f7074696f6e616c2f76)](https://packagist.org/packages/marvin255/optional)[![Total Downloads](https://camo.githubusercontent.com/69237be9e1841c6157d3db2f0b8ce59b07b32abc116dc2dfd769fd859f1d97a4/68747470733a2f2f706f7365722e707567782e6f72672f6d617276696e3235352f6f7074696f6e616c2f646f776e6c6f616473)](https://packagist.org/packages/marvin255/optional)[![License](https://camo.githubusercontent.com/b6a599b93fbf365268613fc4786b4901537de820ab10fdf7cb46bd045149a3bc/68747470733a2f2f706f7365722e707567782e6f72672f6d617276696e3235352f6f7074696f6e616c2f6c6963656e7365)](https://packagist.org/packages/marvin255/optional)[![Build Status](https://github.com/marvin255/optional/workflows/marvin255_optional/badge.svg)](https://github.com/marvin255/optional/actions?query=workflow%3A%22marvin255_optional%22)

PHP implementation of Java's Optional object.

A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.

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

[](#installation)

Install via composer:

```
composer req marvin255/optional
```

Usage
-----

[](#usage)

```
use Marvin255\Optional\Optional;

$optional = Optional::of($input);
if ($optional->isPresent()) {
    $value = $optional->get();
    // do something
}
```

With lambda

```
use Marvin255\Optional\Optional;

Optional::of($input)->ifPresent(function ($item): void {/* do something */});
```

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance87

Actively maintained with recent releases

Popularity17

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 89.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 ~137 days

Recently: every ~166 days

Total

11

Last Release

90d ago

PHP version history (2 changes)v0.1.0PHP &gt;=8.1

v0.2.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c29b776ac327dcfcdfc20619a65826ad94a0cb554503386fb080299edfbe3e8?d=identicon)[marvin255](/maintainers/marvin255)

---

Top Contributors

[![marvin255](https://avatars.githubusercontent.com/u/2802915?v=4)](https://github.com/marvin255 "marvin255 (17 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

optionalphpphpoptional

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/marvin255-optional/health.svg)

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

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21623.4k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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