Fx you

Featured Image: “FIX YOU” by HaoJan is licensed under CC BY-NC 2.0.

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.

[Fix] deprecated: Required parameter follows optional parameter

Sanjeev Aryal

Don't bury your thoughts, put your vision into reality ~ Bob Marley.

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest