by p4bl0 · 2y ago · 0 comments
Not for builtin PHP functions which already throw errors on arity mismatch.
> this would literally break class autoloading in symfony, and even the engine itself, which relies on this feature
I don't understand. Could you point to where in the Symfony code it relies on being able to wrongly call a function with more arguments than it expects and will use?
For variadic functions there is the ... operator already in the language since version 5.6, and my proposal wouldn't break that. Also note that builtin functions already emit deprecated warning in PHP 8 when called with too many arguments.
Here is the full thread discussing it on the PHP internal mailing list: https://news-web.php.net/php.internals/122928
It still only happens during run time. Having a never-called function with an incorrect number of arguments is not an error.
Also, due to the nature and usage of PHP, some things cannot be statically analyzed because they're inherently dynamic. A simple example would be MVC frameworks where the routing is done like so: /controller/action/param1/param2/param3 where "controller" references a class and "action" references a method, which will take the "paramN" as arguments through the splicing of an array: `$ctrl->$actn(...$args);`. In such situations it would be nice to have errors/exceptions raised automatically if the URL is wrong (not enough OR too much arguments) without having to manually assess everything inside each method. Since PHP 7 and 8 over we're moving away from long lines of isset() and !empty() (and verifications such as is_numeric() etc. thanks to argument typing).