Issues

ZF-10114: Undefined index: HTTP_ACCEPT_LANGUAGE

Description

The line


$locale = new Zend_Locale();

triggers a PHP notice: Undefined index: HTTP_ACCEPT_LANGUAGE in Zend/Locale.php on line 430 when the script runs from the CLI mode.

Comments

To expand on this report a little: Zend_Locale::getBrowser() is run every time the class is instantiated, even if a locale is manually passed into the class. In the past, this has not caused any issues because the function just returned an empty array when it wasn't able to detect the locale by "getenv('HTTP_ACCEPT_LANGUAGE')"

However, a recent change (r. 22529) added support for the $_SERVER variable "HTTP_ACCEPT_LANGUAGE" as well. The actual bug is that it assumes this $_SERVER variable is always set, when, in fact, it is not usually set by non-browser clients like cURL unless the developer has set it explicitly. In theory, we just need to make sure the index exists:


$httplanguages = getenv('HTTP_ACCEPT_LANGUAGE');
if (empty($httplanguages) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    $httplanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}

Closing as fixed