componenta/default-value

Default value sentinel for Componenta packages

Maintainers

Package info

github.com/componenta/default-value

pkg:composer/componenta/default-value

Statistics

Installs: 0

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-06-15 10:56 UTC

This package is auto-updated.

Last update: 2026-06-15 12:06:36 UTC


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