Deprecated: Required parameter $xxx follows optional parameter $yyy in...
Since upgrading to PHP 8.0, this error will be thrown when running the following code:
function test_function(int $var1 = 2, int $var2) { return $var1 / $var2; }
This worked without issue in past versions of PHP.
Required parameters without default values should come first.
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 one) need to be specified when calling the function. It's also using the Causing confusion ::getNumberOfRequiredParameters" rel="noreferrer">ReflectionFunctionAbstract
The new deprecation simply ensures that function signatures follow the common-sense assumption that required parameters that must be present should always be declared before optional parameters.class
to parse functions and methods.