This RFC from kylekatarnls adds a clamp() function. You give it a value and two bounds, and if the value falls between them, you get it back unchanged. Otherwise, you get whichever bound is closest. The proposal picks up an earlier clamp RFC that never made it into PHP.

Why it helps

Today you write this logic yourself, usually with min() and max(). The RFC links benchmarks showing that a native function is faster than that approach. It also validates the input for you, catching NAN bounds and a min that's larger than max. Many other languages already ship a clamp function.

How it looks

// Before
$value = max(0, min(100, $percentage));

// After
echo clamp($percentage, min: 0, max: 100);

A few of the RFC's examples:

clamp(2, min: 1, max: 3); // 2
clamp(0, min: 1, max: 3); // 1
clamp(6, min: 1, max: 3); // 3
clamp("a", "c", "g");     // "c"
clamp(NAN, 4, 6);         // NAN

clamp(4, 8, 6);
// ValueError: clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)

The signature is clamp(mixed $value, mixed $min, mixed $max): mixed, and both bounds are inclusive. It accepts any values PHP can compare, so strings and DateTimeImmutable objects work too. Because it follows PHP's standard comparison rules, the same as min() and max(), mixing types can give surprising results, so it's best to pass values of a single type.

If $min or $max is NAN, the function throws a ValueError. If $value is NAN, you get NAN back.

The argument order is value, min, max, which is the most common order in other languages. If you prefer a different order, you can use named arguments:

clamp(min: 0, value: $angle, max: 90);

What it means for existing code

Nothing in PHP itself breaks, but clamp becomes a taken global function name. If your code defines its own global clamp() function, it will clash.

The vote

It passed with 23 votes in favor, 3 against and 6 abstaining, clearing the two-thirds majority it needed. Voting closed on November 18, 2025, and the page says it's implemented in PHP 8.6.