On Wednesday 27 August 2025 17:45:59 (+02:00), Marco Pivetta wrote:
> I know this isn't very used in internals, but does it make sense to
write
> generics for the generated stubs of this function?
> [...]
> /**
> * @template T
> * @param T $value
> * @param T $min
> * @param T $max
> * @return T
> */
> function clamp (mixed $value, mixed $min, mixed $max): mixed {
+1 This is an excellent suggestion. Using a template ensures type
safety and clearly communicates the intended relationship between the
arguments and return value, which is a significant improvement.
This also highlights a minor but important clarification for the
documentation. To make the behavior perfectly unambiguous, I suggest
a small edit to explicitly state the bounds are inclusive.
Current text:
> `clamp` takes three arguments, a `$value`, `$min` and `$max`, then
> checks if `$value` is within the bounds of `$min` and `$max`.
Suggested edit:
> `clamp` takes three arguments, a `$value`, `$min` and `$max`, then
> checks if `$value` is within the bounds of `$min` and `$max` (both
> inclusive).
This is a minimal change that adds crucial clarity already in the first
sentence.
--hakre