Bing Bing - 9 months ago 38
PHP Question

PHP: Why was the `default` parameter RFC rejected?

My apologies if stackoverflow isn't the right place for this. I'm just trying to figure out why the PHP team would vote No on this RFC:

Basically it is suggesting the following code be valid:

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

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

This looks like a great idea to me... why reject it?


Because named_params is a better solution (though this RFC has stalled for 3 years now).

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

Reasons quoted from the 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).

One of the downvoters, @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.