PHPackages                             keerill/php-java-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. keerill/php-java-optional

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

keerill/php-java-optional
=========================

Full implementation of Java8 Optional for PHP

v1.0.2(2y ago)01.6kApache-2.0PHPPHP ^8.1

Since Apr 11Pushed 2y agoCompare

[ Source](https://github.com/popkovkirill/php-java-optional)[ Packagist](https://packagist.org/packages/keerill/php-java-optional)[ Docs](https://github.com/serhatozdal/php-java-optional)[ RSS](/packages/keerill-php-java-optional/feed)WikiDiscussions master Synced 1mo ago

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

keerill/php-java-optional
=========================

[](#keerillphp-java-optional)

Full implementation of JAVA8 Optional for PHP

[![Latest Version on Packagist](https://camo.githubusercontent.com/4ed5a1140417d9535e954c7c812bed334fed0b0dd28cf079e0863ddc7a57bb5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b656572696c6c2f7068702d6a6176612d6f7074696f6e616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/keerill/php-java-optional)[![GitHub Tests Action Status](https://camo.githubusercontent.com/4c5914179f4cb12f32141b31c88a6fc80ed3e0f4b356ac9bbfc10d19b3ee1228/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b656572696c6c2f7068702d6a6176612d6f7074696f6e616c2f72756e2d74657374732e796d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/keerill/php-java-optional/actions?query=workflow%3Arun-tests+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/93f66c6b56c06e03729ab33f6e4be291bfdf6ab861374ec16162411327b34279/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b656572696c6c2f7068702d6a6176612d6f7074696f6e616c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/keerill/php-java-optional)

Usage
-----

[](#usage)

```
// ofEmpty refers Optional#empty() in java
// It is renamed as ofEmpty() because of empty() is reserved by PHP
Optional::ofEmpty()
    ->isPresent(); // false

Optional::of('value')
    ->orElse('elseValue'); // value

Optional::ofEmpty()
    ->orElseThrow(fn () => new InvalidArgumentException()); // throws exception

Optional::ofEmpty()
    ->filter(fn ($a) => (int) $a); // function is not executed

Optional::of(5)
    ->map(fn ($a) => $a * 2)
    ->get(); // returns 10

Optional::ofEmpty()
    ->orElseGet(fn () => 10); // returns 10
```

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

[](#installation)

```
composer require keerill/php-java-optional
```

Resources
---------

[](#resources)

- [Java 8 Optional Documentation](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html)
- [Java 8 Optional Usage](http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

- [kEERIll](https://github.com/kEERill)
- [serhatozdal](https://github.com/serhatozdal)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68% 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 ~123 days

Total

3

Last Release

887d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/920047b57e71b2959cf0934a7d6e45a3a18b639a3bc297cab6e0f0ccb488d535?d=identicon)[kEERill](/maintainers/kEERill)

---

Top Contributors

[![serhatozdal](https://avatars.githubusercontent.com/u/7601151?v=4)](https://github.com/serhatozdal "serhatozdal (17 commits)")[![popkovkirill](https://avatars.githubusercontent.com/u/6718174?v=4)](https://github.com/popkovkirill "popkovkirill (6 commits)")[![keerill](https://avatars.githubusercontent.com/u/74487982?v=4)](https://github.com/keerill "keerill (2 commits)")

---

Tags

java-optionalphp optionalphp java optional

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/keerill-php-java-optional/health.svg)

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

###  Alternatives

[alexwenzel/nova-dependency-container

A Laravel Nova 4 form container for grouping fields that depend on other field values.

461.0M2](/packages/alexwenzel-nova-dependency-container)[micropackage/dochooks

DocHooks - annotated WordPress hooks

3762.4k3](/packages/micropackage-dochooks)[schmeits/filament-pan-analytics-widget

A widget for pan (lightweight and privacy-focused PHP product analytics library)

221.9k](/packages/schmeits-filament-pan-analytics-widget)

PHPackages © 2026

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