title: Why do I get this PHP Warning: "setlocale(): Specified locale name is too long"?
body: <p>When I run this script:</p>
  
  <pre><code>&lt;?php
  $old_locale = setlocale(LC_ALL, '0');
  setlocale(LC_ALL, $old_locale);
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>If I also print <code>$old_locale</code>, it looks like:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I guess the most basic "why" is that I'm trying to pass in a locale string that is indeed too long. In <code>ext/standard/string.c</code> I see:</p>
  
  <pre><code>if (Z_STRLEN_PP(plocale) &gt;= 255) {
      php_error_docref(NULL TSRMLS_CC, E_WARNING, "Specified locale name is too long");
      break;
  }
  </code></pre>
  
  <p>PHP version:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Operating system: up-to-date CentOS release 6.4 (Final)</p>
  
  <p>Output of running <code>locale</code> from the command line:</p>
  
  <pre><code>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=
  </code></pre>
  
  <p>I encountered this PHP warning while working with <a href="https://github.com/goodby/csv/blob/master/src/Goodby/CSV/Import/Standard/Lexer.php#L60" rel="nofollow">Goodby, CSV</a>.</p>