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

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

joelbutcher/php-optional
========================

An opinionated implementation of Java's Optional class for PHP.

v1.0.0(3y ago)143MITPHPPHP ^8.0.2

Since Dec 2Pushed 3y ago1 watchersCompare

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

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

PHP Optional
============

[](#php-optional)

[ ![Build Status](https://github.com/joelbutcher/php-optional/workflows/tests/badge.svg)](https://github.com/joelbutcher/php-optional/actions)[ ![Total Downloads](https://camo.githubusercontent.com/588cb9f25de0595627adca74581668f16b6b5694fb10ddea850465434a811e56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f656c627574636865722f7068702d6f7074696f6e616c)](https://packagist.org/packages/joelbutcher/php-optional)[ ![Latest Stable Version](https://camo.githubusercontent.com/900829bb54e93dab8c99e7745ea16ae6ae8d029a285cc1b3021e05c6a7d0062c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f656c627574636865722f7068702d6f7074696f6e616c)](https://packagist.org/packages/joelbutcher/php-optional)[ ![License](https://camo.githubusercontent.com/c0cadb5328b79ab2d45b335867ca73a240c94300e43accd4bb586b8dacc2faa8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a6f656c627574636865722f7068702d6f7074696f6e616c)](https://packagist.org/packages/joelbutcher/php-optional)Introduction
------------

[](#introduction)

Inspired by Java's [Optional](https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/master/src/java.base/share/classes/java/util/function/Predicate.java) class, this package aims to provide a comprehensive API for optional field values.

Examples
--------

[](#examples)

You can use the `Optional` class in a variety of ways, see below for a few examples:

### Updating a user's profile

[](#updating-a-users-profile)

The below class indicates how this package may be used to update a users profile information. All fields are optional, because our user may not want to update all fields.

```
