P粉6163836252023-08-16 14:16:18
Required parameters without default values should be placed first.
function test_function(int $xxx, int $yyy = 2) { return $xxx * $yyy; }
P粉4516148342023-08-16 09:03:20
This method of function declaration has been deprecated in PHP 8.0. It never makes sense to write a function like this because all arguments (until the last required argument) need to be specified when calling the function. This also led to confusion because of problems using the ReflectionFunctionAbstract
class to analyze functions and methods.
The new deprecation simply ensures that function signatures follow the common sense assumption that required parameters should always be declared before optional parameters.
Functions should be rewritten to remove the default values of previous parameters. Since a function is never called without declaring all its parameters, this has no effect on its functionality.
function test_function(int $var1, int $var2) { return $var1 / $var2; }