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.
Install via composer:
composer req marvin255/optional
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 */});