
This type of error occurs in PHP 8 and higher. This means if you have a function and an optional parameter comes first and then the required param – this deprecation message triggers.
Example. Here $a
is an optional parameter, but $b
is a required parameter which means the required parameter follows optional parameter.
function abc( $a=2, $b ) {
// Omitted for breivity.
}
Why the warning?
because it doesn’t make sense. Does it? You can’t just call the function with a parameter $b
without a parameter $a
.
Fix
You should either make $a
a required parameter or make $a
the second parameter.
function abc( $b, $a=2 ) {
// Omitted for breivity.
}
or, if feasible.
function abc( $a, $b ) {
// Omitted for breivity.
}
The second option should work fine in most conditions. If it doesn’t – consider refactoring the callie.
Also, worth reading >> creation of dynamic property is deprecated since PHP 8.2