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

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

serhatozdal/php-java-optional
=============================

Full implementation of Java8 Optional for PHP

1.0(8y ago)11.2k1Apache-2.0PHPPHP &gt;=5.5.0

Since Apr 14Pushed 8y ago2 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

serhatozdal/php-java-optional
=============================

[](#serhatozdalphp-java-optional)

Full implementation of JAVA8 Optional for PHP

[![Build Status](https://camo.githubusercontent.com/06e7de41226d1c9aef4d306e8c77860692ccf82b3b6a3afc2a139015aeff083d/68747470733a2f2f7472617669732d63692e6f72672f7365726861746f7a64616c2f7068702d6a6176612d6f7074696f6e616c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/serhatozdal/php-java-optional)[![Latest Stable Version](https://camo.githubusercontent.com/e3a6fc5f543e8fbb09d30bc6367394589b797caba26b0c2e1b7fd572ccd7d9bf/68747470733a2f2f706f7365722e707567782e6f72672f7365726861746f7a64616c2f7068702d6a6176612d6f7074696f6e616c2f762f737461626c65)](https://packagist.org/packages/serhatozdal/php-java-optional)[![Latest Unstable Version](https://camo.githubusercontent.com/242f21c3d2c55a73ef99c9c47e2e0d12e74c2287fa7db6680dd829e92d94a69a/68747470733a2f2f706f7365722e707567782e6f72672f7365726861746f7a64616c2f7068702d6a6176612d6f7074696f6e616c2f762f756e737461626c65)](https://packagist.org/packages/serhatozdal/php-java-optional)[![GitHub license](https://camo.githubusercontent.com/58430f2a87002e58892cca5ebd12dbce93bcb77073db4902486805ba86df8fd9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7365726861746f7a64616c2f7068702d6a6176612d6f7074696f6e616c2e737667)](https://github.com/serhatozdal/php-java-optional/blob/master/LICENSE)

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(function () { throw .... }); // throws exception

Optional::ofEmpty()->filter(function ($a) { return (int) $a; }); // function is not executed

Optional::of(5)->map(function ($a) { return $a * 2; })->get(); // returns 10

Optional::ofEmpty()->orElseGet(function () { return 10; }); // returns 10
```

Installation
============

[](#installation)

```
composer require serhatozdal/php-java-optional:1.0
```

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)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

2953d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a08588efa9ac5db631634841c922f15d57b9edfeb53231b63374c1e3cc4e701e?d=identicon)[serhatozdal](/maintainers/serhatozdal)

---

Top Contributors

[![serhatozdal](https://avatars.githubusercontent.com/u/7601151?v=4)](https://github.com/serhatozdal "serhatozdal (17 commits)")

---

Tags

java-optionalphp optionalphp java optional

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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