rimantasrickus / optional
Optional values for PHP
dev-main
2024-09-01 13:45 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpstan/phpstan: ^1.2
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2025-03-29 01:08:26 UTC
README
Simple class to add Optional type for scalar values.
Before returning value it will always check if value is null.
Additionally to this check you can add your own filter class to check for example for empty strings.
<?php use Optional\Optional; use Optional\Filters\ZeroIntFilter; require_once 'vendor/autoload.php'; $optional = new Optional(rand(0, 1)); printf( "value: %s\n", $optional ->withFilter(new ZeroIntFilter()) ->orDefault('empty') );