Hi Kim Hallberg, > The RFC for the clamp function is now open and under discussion, you now have > 2 weeks > to discuss, suggest improvements and open issues before voting is considered. > > Any and all feedback is welcomed. > > The RFC is available for viewing here: https://wiki.php.net/rfc/clamp > The implementation is available in a PR here: > https://github.com/php/php-src/pull/7191
https://wiki.php.net/rfc/howto mentions: > Listen to the feedback, and try to answer/resolve all questions. > **Update your RFC to document all the issues and discussions. > Cover both the positive and negative arguments.** Put the RFC URL into all > your replies. So I think the major objections are that: 1. This is easy to implement in userland and there's negligible performance benefit (in code that is a performance sensitive loop, it may still be worse compared to `$num < $min ? $min : ($num > $max : $max : $num)` when validity of types and min/max are known, especially with the JIT) 2. People not being sure if they'd ever use it personally, especially with the ability to customize parameter order and permitted argument types in userland 3. It's inconsistent with min() and max(), which support any comparable type such as GMP(https://www.php.net/manual/en/class.gmp) (arbitrary precision numbers), DateTime, etc., and that may lead to surprises. Although PHP's comparison operator and https://www.php.net/manual/en/function.min.php have many, many inconsistencies, already (Though special casing GMP is probably a bad idea due to it being optional and having an incompatible license with core for packagers) 4. I'm not sure what this is meant to do with the float NAN (Not A Number) from the RFC description, but that's solvable ``` php > var_dump(min(gmp_init('123'), gmp_init('456'))); object(GMP)#1 (1) { ["num"]=> string(3) "123" } php > var_dump(max(new DateTime('@0'), new DateTime())); object(DateTime)#2 (3) { ["date"]=> string(26) "2021-06-23 23:44:47.302531" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } php > echo json_encode(max([0,2],[0,1])); [0,2] ``` The RFC should probably link to this RFC announcement thread https://externals.io/message/115076 as well. Thanks, Tyson -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php