PHP 8.6 is adding a clamp() function, and it is the kind of small standard-library change I tend to like. It takes a value plus minimum and maximum bounds, returns the value when it is already inside the range, and otherwise returns the nearest boundary. Nothing clever, just one less helper to rewrite.
The PHP 8.6 clamp documentation shows the obvious cases: clamp(105, 0, 100) returns 100, while clamp(-5, 0, 100) returns 0. The bounds are inclusive and a minimum greater than the maximum throws a ValueError. It works with more than integers and floats, although PHP’s mixed-type comparison rules mean I would keep its use firmly inside well-typed code.
The practical win is readability. clamp($percentage, 0, 100) says what the code is doing more clearly than a nested combination of min() and max(), especially when somebody has to remember which one goes inside. It is useful for percentages, pagination limits, coordinates, UI values, and plenty of small validation paths.
There is a possible naming collision because clamp lives in the global namespace, so projects with an existing helper should check before upgrading. Otherwise this is pleasantly uneventful. PHP does not need every release feature to change how applications are designed. Sometimes removing a familiar five-line helper from thousands of codebases is enough.