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

Abandoned → [https://github.com/silasyudi/optional](/?search=https%3A%2F%2Fgithub.com%2Fsilasyudi%2Foptional)Library[Utility &amp; Helpers](/categories/utility)

symfonyboot/optional
====================

Portability of Java's java.util.Optional&lt;T&gt; class to PHP.

v2.0.0(4y ago)016MITPHPPHP &gt;=7.4

Since Mar 23Pushed 4y agoCompare

[ Source](https://github.com/silasyudi/optional)[ Packagist](https://packagist.org/packages/symfonyboot/optional)[ RSS](/packages/symfonyboot-optional/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Optional
========

[](#optional)

[![Tests](https://github.com/silasyudi/optional/actions/workflows/tests.yml/badge.svg)](https://github.com/silasyudi/optional/actions/workflows/tests.yml)[![Maintainability](https://camo.githubusercontent.com/cdc47c95fb4fef00c4354587f6b21044eb7f72328fcb8c4f34ffe1bd254bbb81/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f32326165666439613134366162646536386166642f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/silasyudi/optional/maintainability)[![Test Coverage](https://camo.githubusercontent.com/8ddf48b052613c7e4d9dbb0f78ef83f70da1fdd4b0475011e3c72ce46eb5a7d7/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f32326165666439613134366162646536386166642f746573745f636f766572616765)](https://codeclimate.com/github/silasyudi/optional/test_coverage)

Portability of Java's `java.util.Optional` class to PHP, updated with Java 11 features.

Summary
-------

[](#summary)

- [Language / Idioma](#language--idioma)
- [Instalation](#instalation)
- [Requirements](#requirements)
- [Features](#features)
- [Differences](#differences)

Language / Idioma
-----------------

[](#language--idioma)

Leia a versão em português 🇧🇷 [aqui](README_PT_BR.md).

Instalation
-----------

[](#instalation)

```
composer require silasyudi/optional
```

Requirements
------------

[](#requirements)

- PHP 7.4+
- Composer

Features
--------

[](#features)

The Optional class encapsulates a value and can perform various operations on it.

### Example without Optional:

[](#example-without-optional)

```
    /** @var Entity|null $entity */
    $entity = $this->repository->find($id);

    if (!$entity) {
        throw new SomeException();
    }

    ...
```

### Example with Optional:

[](#example-with-optional)

```
    /** @var SilasYudi\Optional $optional */
    $optional = $this->repository->find($id);
    $entity = $optional->orElseThrow(new SomeException());
    ...
```

Differences
-----------

[](#differences)

Some differences could not be avoided due to the particularities of each language. The most important are listed below:

- `Optional.stream()` of the Java was not imported into this package, as it doesn't have something similar in PHP and already has similar methods in `map`, `flatMap` and `filter`.
- `Optional.hashCode()` was not imported into this package.
- `NullPointerException` e `NoSuchElementException` of the Java was replaced by `OptionalInvalidStateException`when the Optional object cannot be empty and `TypeError` when attempting to pass null in `callable` parameters.
- `Optional.orElseThrow` in Java 11 is overloaded, and expects no parameter or a Supplier parameter. In this package, this method expects a Throwable object or `null` as parameter.
- `Consumer`, `Function`, `Predicate` and `Supplier` was imported as `callable`.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

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 ~26 days

Total

3

Last Release

1465d ago

Major Versions

v1.0.1 → v2.0.02022-05-14

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/4693297?v=4)[Silas Yudi](/maintainers/silasyudi)[@silasyudi](https://github.com/silasyudi)

---

Top Contributors

[![silasyudi](https://avatars.githubusercontent.com/u/4693297?v=4)](https://github.com/silasyudi "silasyudi (6 commits)")

---

Tags

libraryoptionalphpoptionaljava

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[nervo/yuicompressor

YUI Compressor is an open source tool that supports the compression of both JavaScript and CSS files. The JavaScript compression removes comments and white-spaces as well as obfuscates local variables using the smallest possible variable name. CSS compression is done using a regular-expression-based CSS minifier.

161.5M5](/packages/nervo-yuicompressor)[soluble/japha

Soluble PHP Java bridge integration

7343.5k3](/packages/soluble-japha)[javadev/moneytostr-russian

The tool to convert amount to words in Ukrainian/English/Russian languages

421.2k](/packages/javadev-moneytostr-russian)

PHPackages © 2026

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