Usephul

Fallback
in package

A unit enum representing a fallback type.

It is inhabited by exactly one case: Fallback::default.

Conceptually, Fallback::default indicates the lack of an operation having been performed on a variable. This is useful in cases where any value is otherwise valid, and you need to distinguish between "no value provided" and "value explicitly set to null".

The Fallback::default case is also aliased as the constant fallback for convenience.

You can also use the Fallback enum as a type hint:

function example(string|null|Fallback $param = fallback): void }

And you can use the Fallback::default case or the fallback const as a default value for functions that attempt to retrieve a value without a guarantee, and accept a $default argument:

$value = config('some_key', fallback);
if ($value === fallback) {
    // 'some_key' was not found
}

Table of Contents

Cases

default
The default fallback case.

Cases


        
On this page

Search results