getParamNumberRange.php
Table of Contents
Functions
- getParamNumberRange() : int|float|null
- Retrieves a numeric parameter from the request and clamps it within a given range.
Functions
getParamNumberRange()
Retrieves a numeric parameter from the request and clamps it within a given range.
getParamNumberRange(ServerRequestInterface|null $request, string $name, int|float $min, int|float $max[, int|float|null $defaultValue = null ][, array<string|int, mixed> $args = [] ][, string $strategy = HttpParamStrategy::BOTH ][, bool $throwable = false ]) : int|float|null
This helper calls getParam() and:
- Converts the value to int or float.
- Returns
$defaultValueif the parameter is missing or not numeric. - Clamps the value between
$minand$max. - Can throw NotFoundException if
$throwableis true and parameter is missing.
Parameters
- $request : ServerRequestInterface|null
-
The PSR-7 request instance.
- $name : string
-
Parameter name or dot-notated path.
- $min : int|float
-
Minimum allowed value.
- $max : int|float
-
Maximum allowed value.
- $defaultValue : int|float|null = null
-
Value returned if missing or invalid. Default null.
- $args : array<string|int, mixed> = []
-
Optional defaults passed to getParam().
- $strategy : string = HttpParamStrategy::BOTH
-
Source to search: BOTH, QUERY, BODY. Default BOTH.
- $throwable : bool = false
-
Whether to throw NotFoundException if missing. Default false.
Tags
Return values
int|float|null —The numeric value clamped to the range [$min, $max], or $defaultValue/null if missing or invalid.