On Thu, Apr 4, 2024 at 5:58 PM Tim Düsterhus <t...@bastelstu.be> wrote: > > On 4/4/24 16:36, Pablo Rauzy wrote: > > I strongly agree in theory, but this could break existing code, and > > moreover such a proposal was already rejected: > > https://wiki.php.net/rfc/strict_argcount > > The RFC is 9 years old by now. My gut feeling is be that using an actual > variadic parameter for functions that are variadic is what people do, > because it makes the function signature much clearer. Actually variadic > parameters are available since PHP 5.6, which at the time of the > previous RFC was the newest version. Since then we had two major > releases, one of which (7.x) is already out of support. > > I think it would be reasonable to consider deprecating passing extra > arguments to a non-variadic function.
IIRC one of the bigger downsides of this change are closure calls that may provide arguments that the callee does not care about. https://3v4l.org/0QdoS ``` function filter($array, callable $c) { $result = []; foreach ($array as $key => $value) { if ($c($value, $key)) { $result[$key] = $value; } } return $result; } var_dump(filter(['foo', '', 'bar'], function ($value) { return strlen($value); })); // Internal functions already throw on superfluous args var_dump(filter(['foo', '', 'bar'], 'strlen')); ``` The user may currently choose to omit the $key parameter of the closure, as it is never used. In the future, this would throw. We may decide to create an exemption for such calls, but I'm not sure replacing one inconsistency with another is a good choice. Ilija