|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69481 how php initializes locale is not documented
Submitted: 2015-04-19 08:11 UTC Modified: -
From: glen at delfi dot ee Assigned:
Status: Open Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-04-19 08:11 UTC] glen at delfi dot ee
seems php initializes ONLY LC_CTYPE from enviroment, leaving default behaviour that declaring LC_ALL value overrides any other category BROKEN:

this seems to be related to some experiment done in 2000 and then reverted:

the fact that there even is setlocale(LC_CTYPE, "") done unconditionally in php init, is not documented.

but i think it should be either:
1. no unconditional setlocale() call at all
2. setlocale(LC_ALL, "");
3. setlocale(LC_ALL, "C");

the last one is probably the worst.

Test script:
compare how system date command behaves and how php behaves:

test1: only LC_ALL env var is set, but php resets LC_CTYPE, meaning LC_CTYPE gets env value, the other categories get reset to C:

$ env -i LC_ALL=et_EE.utf8 php -r 'var_dump(setlocale(LC_ALL, 0)); passthru("set -x;env;date +%A%d.%B"); echo "\nPHP:", strftime("%A, %d. %B"), "\n";'
+ env
+ date +%A%d.%B

PHP:Sunday, 19. April

test2: if php would do setlocale(LC_ALL, "") instead of setlocale(LC_CTYPE, ""), then result is as expeted, LC_ALL overrides all categories. shell and php behaviour matches:

$ env -i LC_ALL=et_EE.utf8 php -r 'setlocale(LC_ALL, ""); var_dump(setlocale(LC_ALL, 0)); passthru("set -x;env;date +%A%d.%B"); echo "\nPHP:", strftime("%A, %d. %B"), "\n";'
string(10) "et_EE.utf8"
+ env
+ date +%A%d.%B

PHP:pühapäev, 19. aprill


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jul 29 08:01:23 2021 UTC