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

标签 php

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

相关文章:

php - 使用PHP将2个数组插入mysql

php - 清理数据 PHP 函数

php - 如何验证服务器调用是从应用程序发出的?

javascript - 验证后的 jQuery 动态字段消失

PHP:从php文件中获取PHP的变量、函数、常量

php - PracticeController.php 第 0 行中的 FatalErrorException:方法 Illuminate\Database\Eloquent\Collection::__toString() 不得引发异常**

php - 使用 jQuery 和 PHP 进行 HTML 5 拖放上传

javascript - 当不显示 div 时,忘记这个 css 规则

PHP MySQL Search between with an "or"condition

php - 使用 DB::raw 和 Eloquent 使用相同查询的不同结果