如果 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/