gpt4 book ai didi

PHP:为什么 `default` 参数 RFC 被拒绝?

转载 作者:搜寻专家 更新时间:2023-10-31 21:25:19 25 4
gpt4 key购买 nike

如果 stackoverflow 不适合这个,我深表歉意。我只是想弄清楚为什么 PHP 团队会对这个 RFC 投票:https://wiki.php.net/rfc/skipparams

基本上它建议以下代码是有效的:

function foo($a, $b = "2", $c = "3") {
echo "$a $b $c";
}

foo(1, default, 5); // prints "1 2 5"

这对我来说是个好主意……为什么要拒​​绝它?

最佳答案

因为 named_params是一个更好的解决方案(尽管这个 RFC 现在已经停滞了 3 年)。

htmlspecialchars($string, default, default, false);
// vs
htmlspecialchars($string, double_encode => false);

引用自 php-internals mailing list 的原因:

Basically, even though not having to specify the default-value for some parameters could be useful in some situations, this approach doesn't feel right and we would really prefer something like named-parameters (even if this RFC is not incompatible with named-parameters and they most likely won't make it for PHP 7.0).

反对者之一,@philstu,also blogged ,

While I am glad Stas went to the trouble of making this, I am so much more glad that people downvoted it. It’s a band aid solution to named parameters, and I really hope we see them for later versions of PHP 7.x.

关于PHP:为什么 `default` 参数 RFC 被拒绝?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37537862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com