PHPackages                             unicorn-fail/php-option - 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. unicorn-fail/php-option

ActiveLibrary

unicorn-fail/php-option
=======================

A highly extensible replacement for \[phpoption/phpoption\] with `TypedOption` support.

1.6.0(6y ago)226Apache-2.0PHPPHP &gt;=5.3

Since Nov 13Pushed 6y agoCompare

[ Source](https://github.com/unicorn-fail/php-option)[ Packagist](https://packagist.org/packages/unicorn-fail/php-option)[ RSS](/packages/unicorn-fail-php-option/feed)WikiDiscussions master Synced 3d ago

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

unicorn-fail/php-option
=======================

[](#unicorn-failphp-option)

> A highly extensible replacement for [phpoption/phpoption](https://packagist.org/packages/phpoption/phpoption) with `TypedOption` support.

[![Latest Version](https://camo.githubusercontent.com/520ab4de36de013625348481b320c16ecbc7c18316310b237ab9389531b24e6f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f756e69636f726e2d6661696c2f7068702d6f7074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/unicorn-fail/php-option)[![Total Downloads](https://camo.githubusercontent.com/a20bf5f134ee21179d3e51c28c296f18ff14adcc49b973182d1556cd276c9573/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f756e69636f726e2d6661696c2f7068702d6f7074696f6e2e7376673f7374796c653d666c61742d73717561726526636f6c6f723d626c7565)](https://packagist.org/packages/unicorn-fail/php-option)[![License](https://camo.githubusercontent.com/bda9c4d14c9731b392b788c3dc00353dabcf6ad5d290170632a1fe95f29b5469/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f756e69636f726e2d6661696c2f7068702d6f7074696f6e3f636f6c6f723d626c7565267374796c653d666c61742d737175617265)](LICENSE)[![PHP from Packagist](https://camo.githubusercontent.com/263ee8764961556d88ddfd6ae12714c51270b943a790ad0f1ea2528e86949131/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f756e69636f726e2d6661696c2f7068702d6f7074696f6e3f7374796c653d666c61742d737175617265)](https://travis-ci.com/unicorn-fail/php-option)

[![Build Status](https://camo.githubusercontent.com/0d774f32db0bb2777403547714c3fc973711d18f76bba6000f6139b5799c3469/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f756e69636f726e2d6661696c2f7068702d6f7074696f6e2e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/unicorn-fail/php-option)[![Codacy grade](https://camo.githubusercontent.com/1f23d152cff8bbbc4788184018221d3834ff250de9be2479f79b8f352c8c6a03/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f67726164652f33393630393939353536303834306532383266643430316236636539316234663f7374796c653d666c61742d737175617265)](https://www.codacy.com/app/unicorn-fail/php-option?utm_source=github.com&utm_medium=referral&utm_content=unicorn-fail/php-option&utm_campaign=Badge_Grade)[![Codacy coverage](https://camo.githubusercontent.com/4098decb7fffa013e5367fd3be44c822210c45fead17c31e46e5040111af8c5b/68747470733a2f2f696d672e736869656c64732e696f2f636f646163792f636f7665726167652f33393630393939353536303834306532383266643430316236636539316234663f7374796c653d666c61742d737175617265)](https://www.codacy.com/app/unicorn-fail/php-option?utm_source=github.com&utm_medium=referral&utm_content=unicorn-fail/php-option&utm_campaign=Badge_Coverage)[![phpcs coding standard](https://camo.githubusercontent.com/8d94bdfdcb4814dba804189bb9b29baf2a5a597fbcb2cc21b37195e99a657698/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70687063732d505352322d627269676874677265656e3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8d94bdfdcb4814dba804189bb9b29baf2a5a597fbcb2cc21b37195e99a657698/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f70687063732d505352322d627269676874677265656e3f7374796c653d666c61742d737175617265)

An `Option` is intended for cases where you sometimes might return a value (typically an object), and sometimes you might return no value (typically null) depending on arguments, or other runtime factors.

Often times, you forget to handle the case where no value is returned. Not intentionally of course, but maybe you did not account for all possible states of the system; or maybe you indeed covered all cases, then time goes on, code is refactored, some of these your checks might become invalid, or incomplete. Suddenly, without noticing, the no value case is not handled anymore. As a result, you might sometimes get fatal PHP errors telling you that you called a method on a non-object; users might see blank pages, or worse.

On one hand, an `Option` forces a developer to consciously think about both cases (returning a value, or returning no value). That in itself will already make your code more robust. On the other hand, the `Option` also allows the API developer to provide more concise API methods, and empowers the API user in how he consumes these methods.

📦 Installation
--------------

[](#-installation)

This project can be installed via [Composer](https://getcomposer.org/):

```
$ composer require unicorn-fail/php-option
```

Basic Usage
-----------

[](#basic-usage)

### Using `Option` in your API

[](#using-option-in-your-api)

```
