已弃用:setlocale():已弃用将区域设置类别名称作为字符串传递。使用 LC_

Deprecated: setlocale(): Passing locale category name as string is deprecated. Use the LC_

随着 PHP 的新更新发布,他们似乎删除了 LC_MESSAGESLC_ALLLC_COLLATELC_CTYPELC_MONETARYLC_NUMERICLC_TIME 必须改用,我已将我的 LC_MESSAGES 更改为 LC_ALL 但我收到此错误:

Deprecated: setlocale(): Passing locale category name as string is deprecated. Use the LC_* -constants instead

这是我的代码供参考:

public static function gettext()
{
    //include the libs
    include(Config::get('PATH_LIBS')."streams.php");
    include(Config::get('PATH_LIBS')."gettext.php");

    //define all the language settings
    define('LOCALE', 'en_GB');
    define('SESSION_LOCALE_KEY', 'locale');
    define('DEFAULT_LOCALE', 'en_GB');
    define('LOCALE_REQUEST_PARAM', 'lang');
    define('WEBSITE_DOMAIN', 'messages');

    //check if the language exists
    if(array_key_exists(LOCALE_REQUEST_PARAM, $_REQUEST)):
            $current_locale = $_REQUEST[LOCALE_REQUEST_PARAM];
            $_COOKIE[SESSION_LOCALE_KEY] = $current_locale;
    elseif(array_key_exists(SESSION_LOCALE_KEY, $_COOKIE)):
            $current_locale = $_COOKIE[SESSION_LOCALE_KEY];
    else:
            $current_locale = DEFAULT_LOCALE;
    endif;

    //will eventually stick this all in the model file
    putenv("LC_TIM=en_GB");
    putenv("LC_MESSAGES=$current_locale");
    setlocale('LC_ALL', $current_locale);

    //bind it all 
    bindtextdomain(WEBSITE_DOMAIN, Config::get('PATH_MAIN').'lang/');
    bind_textdomain_codeset(WEBSITE_DOMAIN, 'UTF-8');
    textdomain(WEBSITE_DOMAIN);
}

错误显示 "passing locale category name as string is deprecated"。看看你在做什么:

setlocale('LC_ALL', $current_locale);

您将语言环境类别作为字符串传递。改用预定义常量:

setlocale(LC_ALL, $current_locale);
// Look ma, ^^ no quotes!

如果缺少 LC_MESSAGES,则此代码段 from the manual 可能相关:

  • LC_MESSAGES for system responses (available if PHP was compiled with libintl)

libintl 可能不是用你的 PHP.

编译的