当我运行这个脚本时:
<?php
$old_locale = setlocale(LC_ALL, '0');
setlocale(LC_ALL, $old_locale);
我得到:
PHP Warning: setlocale(): Specified locale name is too long in /tmp/loc.php on line 3
PHP Stack trace:
PHP 1. {main}() /tmp/loc.php:0
PHP 2. setlocale() /tmp/loc.php:3
如果我也 print $old_locale
,它看起来像:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8
我想最基本的“为什么”是我试图传递一个确实太长的语言环境字符串。在ext/standard/string.c
我看到:
if (Z_STRLEN_PP(plocale) >= 255) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified locale name is too long");
break;
}
PHP版本:
PHP 5.4.13 (cli) (built: Mar 15 2013 11:27:51)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans
操作系统:最新的 CentOS 版本 6.4 (Final)
locale
从命令行运行的输出:
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
我在使用Goodby, CSV时遇到了这个 PHP 警告。