glFusion / glfusion

glFusion CMS - Advanced Content Management with Style
https://www.glfusion.org
GNU General Public License v2.0
14 stars 15 forks source link

Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in lib-common.php:5476 #519

Open mark0263 opened 2 years ago

mark0263 commented 2 years ago

When loading the site - the subject error hits. Appears to only happen on PHP v8+ sites. The code below will resolve the issue by validating $_CONF['language_files'] is actually an array that is set.

function COM_getLanguageFromBrowser()
{
    global $_CONF;

    $retval = '';

    if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        $accept = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        foreach ($accept as $l) {
            $l = explode(';', trim($l));
            $l = $l[0];
            if (is_array($_CONF['language_files']) && @array_key_exists($l, $_CONF['language_files'])) {
                $retval = $_CONF['language_files'][$l];
                break;
            } else {
                $l = explode('-', $l);
                $l = $l[0];
                if (is_array($_CONF['language_files']) && @array_key_exists($l, $_CONF['language_files'])) {
                    $retval = $_CONF['language_files'][$l];
                    break;
                }
            }
        }
    }

    return $retval;
}