goodby/csv

setlocale() call issues PHP Warning on CentOS 6.4, PHP 5.4.13

meonkeys opened this issue · 2 comments

I'm getting a PHP Warning from csv/src/Goodby/CSV/Import/Standard/Lexer.php line 60:

PHP Warning:  setlocale(): Specified locale name is too long

I wrote a little test script to see what's getting passed to setlocale():

<?php
$originalLocale = setlocale(LC_ALL, '0');
echo "$originalLocale\n";

This outputs:

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

From ext/standard/string.c in the PHP source, I see:

if (Z_STRLEN_PP(plocale) >= 255) {
    php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified locale name is too long");
    break;
}

It appears this would be correct:

setlocale(LC_ALL, 'en_US.UTF-8');

But that's not portable... maybe we can parse $originalLocale and pass in an array to setlocale()?

PHP version:

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

Operating system: up-to-date CentOS release 6.4 (Final)

See also: http://stackoverflow.com/questions/16110866/why-do-i-get-this-php-warning-setlocale-specified-locale-name-is-too-long

WARNING: I only tested this on my machine. I don't have OS X or Windows, but it should probably be tested on those too.

See issue #13