marvin255 / optional
Optional container for PHP.
v0.2.1
2025-05-10 11:01 UTC
Requires
- php: >=8.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.29
- phpunit/phpunit: ^12.0
- vimeo/psalm: ^6.0
This package is auto-updated.
Last update: 2025-05-10 11:20:14 UTC
README
PHP implementation of Java's Optional object.
A container object which may or may not contain a non-null value. If a value is present, isPresent() will return true and get() will return the value.
Installation
Install via composer:
composer req marvin255/optional
Usage
use Marvin255\Optional\Optional; $optional = Optional::of($input); if ($optional->isPresent()) { $value = $optional->get(); // do something }
With lambda
use Marvin255\Optional\Optional; Optional::of($input)->ifPresent(function ($item): void {/* do something */});