azjezz/psl
PSL is a modern, well-typed standard library for PHP 8.4+, inspired by HHVM’s HSL. It offers safer, predictable APIs for async, collections, networking, I/O, crypto, terminal UI, and robust data validation—replacing brittle built-ins with consistent alternatives.
The Option component represents a value that may or may not be present. It replaces nullable types (?T) with explicit Some/None semantics, making the absence of a value intentional and impossible to ignore.
Instead of returning null and hoping callers remember to check, you return an Option that forces the caller to handle both cases.
Option<T> is a single readonly class with two states:
Option::some($value) -- A value is presentOption::none() -- No value is presentConvenience functions some(), none(), and from_nullable() are available in the Psl\Option namespace.
@example('types/option-creating.php')
@example('types/option-checking.php')
@example('types/option-transforming.php')
Handle both cases and return a unified result:
@example('types/option-proceed.php')
Run a closure on the value without changing the Option:
@example('types/option-apply.php')
@example('types/option-filtering.php')
@example('types/option-combining.php')
find_by_id() returns Option<Entity> instead of ?Entityget_setting() returns Option<string> -- absence is explicitandThen() to chain fallible lookups without nested null checksfrom_nullable() and transform with map()See src/Psl/Option/ for the full API.
How can I help you explore Laravel packages today?