Warning error log php deprecated

Erassus ︎ ︎ Posted in Technical Support 3 years ago

Hi Community, after i upgraded to PHP 8 in my prod environment, i have this spam error log (doesnt stop) site doesnt crash but the error_log file is growing.

PHP Deprecated:  Optional parameter $code declared before required parameter $file is implicitly treated as a required parameter in /public_html/libraries/ossn.lib.languages.php on line 18

I found this: https://php.watch/versions/8.0/deprecate-required-param-after-optional

Code:

function ossn_register_language($code = '', $file) {
    if(isset($code) && isset($file)) {
            global $Ossn;
            $Ossn->locale[$code][] = $file;
    }

}

How i can fix this? any advices are welcomed.

Replies
cl Erassus ︎ ︎ Replied 3 years ago

Hi Michael,

Thanks for the suggestion, I'll keep it in mind if I find errors again and i willreport them to OT.

Also error_log is very useful, I'll try it with other components.

I edited the line and now it works fine.

This post can be helpful if anyone upgraded and found some warnings.

German Michael Zülsdorff Replied 3 years ago

As a first step I would temporarely log $code and $file like

function ossn_register_language($code = '', $file) {
error_log('CODE ' . $code . ' FILE ' . $file);
        if(isset($code) && isset($file)) {
                global $Ossn;
                $Ossn->locale[$code][] = $file;
        }
}

Of course this would give even more lines in your log file,
but hopefully you'll know afterwards WHEN the warning occurs and pass it to Openteknik

Next, I'd change the code like

function ossn_register_language($code, $file) {
        if(isset($code) && isset($file)) {
                global $Ossn;
                $Ossn->locale[$code][] = $file;
        }
}