PHPackages                             mareg/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mareg/option

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

mareg/option
============

0.2.3(9y ago)018.3k↓47.3%3PHP

Since Mar 1Pushed 9y ago1 watchersCompare

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

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

Option
======

[](#option)

[![Build Status](https://camo.githubusercontent.com/7755e35b755f2e0abb05878152cc478f471ff316edd1751b7eb2ab1915fac7e7/68747470733a2f2f7472617669732d63692e6f72672f4a6f736570684d6f6e697a2f7068702d6f7074696f6e2e706e673f6272616e63683d6d6173746572)](undefined)

Strongly typed alternative to null. The Option type in this package is based off of the Option typeclass from Scala and the Maybe monad from Haskell.

`Option` itself is just an interface. Two classes in this package implement the `Option` interface and they are `Some` and `None`. The convention is to have functions return `Option` types and it will either contain `Some` value or `None` at all. This creates a type safe alternative to returning null in the absence of a value.

In addition to the added type safety, the `Option` type is monadic, so `Option` types are highly composable. This allows you to eliminate a lot of the typical null checking boiler plate code you'd normally have to write and encourages you to write in a more expressive style.

```
