goodby / csv

Goodby CSV is a high memory efficient flexible and extendable open-source CSV import/export library for PHP 5.3. 1. Memory Management Free This library designed for memory unbreakable. It will not be accumulated in the memory whole rows. The importer read CSV file and execute callback function line by line. 2. Multibyte support This library supports mulitbyte input/output: for example, SJIS-win, EUC-JP and UTF-8. 3. Ready to Use for Enterprise Applications Goodby CSV is fully unit-tested. The library is stable and ready to be used in large projects like enterprise applications.
MIT License
953 stars 147 forks source link

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

Closed meonkeys closed 11 years ago

meonkeys commented 11 years ago

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

meonkeys commented 11 years ago

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.

meonkeys commented 11 years ago

See issue #13