Zend Framework

Undefined index: HTTP_ACCEPT_LANGUAGE

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.10.7
  • Fix Version/s: 1.10.7
  • Component/s: Zend_Locale
  • Labels:
    None

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.

Activity

Hide
Andrew Bredow added a comment -

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:

Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
$httplanguages = getenv('HTTP_ACCEPT_LANGUAGE');
if (empty($httplanguages) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    $httplanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
Show
Andrew Bredow added a comment - 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:
Unable to find source-code formatter for language: php. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
$httplanguages = getenv('HTTP_ACCEPT_LANGUAGE');
if (empty($httplanguages) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
    $httplanguages = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
}
Hide
Thomas Weidner added a comment -

Closing as fixed

Show
Thomas Weidner added a comment - Closing as fixed

People

Vote (2)
Watch (4)

Dates

  • Created:
    Updated:
    Resolved: