Deprecated: setlocale():不赞成将区域类别名称作为字符串传递.使用LC_


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

随着PHP的新更新出来,似乎他们已经删除了LC_MESSAGESLC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY, LC_NUMERICLC_TIME必须使用,我已经将我的LC_MESSAGES更改为LC_ALL,但我收到此错误:

已弃用:setlocale():将区域类别名称作为字符串is传递弃用。使用LC_* -常量代替

下面是我的代码供参考:

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);
}

错误提示"不支持将区域设置类别名称作为字符串传递"。看看你在做什么:

setlocale('LC_ALL', $current_locale);

您正在将区域设置类别作为字符串传递。请使用预定义的常量:

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

如果缺少LC_MESSAGES,则手册中的这段代码可能是相关的:

  • LC_MESSAGES用于系统响应(如果PHP是用libintl编译的)

libintl可能不是用你的PHP编译的