componenta / default-value
Default value sentinel for Componenta packages
v1.0.0
2026-06-15 10:56 UTC
Requires
- php: ^8.4
Requires (Dev)
- pestphp/pest: ^4.0
- phpunit/phpunit: ^12.0
README
Single marker enum for distinguishing an omitted default value from an explicit null.
Use it in APIs where null is a meaningful caller-provided value and cannot also mean "argument was not provided".
Installation
composer require componenta/default-value
Related Packages
| Package | Why it matters here |
|---|---|
componenta/di |
Uses DefaultValue::None in attributes where null can be an explicit default. |
componenta/config |
Useful for APIs that distinguish an omitted fallback from a null fallback. |
Usage
use Componenta\Stdlib\DefaultValue; function readOption(string $name, mixed $default = DefaultValue::None): mixed { if ($default === DefaultValue::None) { return loadRequiredOption($name); } return loadOptionalOption($name, $default); }
Passing null remains explicit:
readOption('cache.ttl', null); // default is intentionally null
Contract
DefaultValue::None means no default value was provided. It is intentionally a marker, not a container and not a replacement for Option/Maybe value objects.
When To Use
Use this package for function arguments, resolver APIs, config helpers, and factories that need to preserve the difference between:
- no fallback was given
- fallback was given and the fallback is
null