php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39993 tr_TR.UTF-8 locale has problems with PHP
Submitted: 2006-12-30 18:22 UTC Modified: 2007-01-18 23:20 UTC
From: tunix at raptiye dot org Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.2.0 OS: Arch Linux
Private report: No CVE-ID: None
 [2006-12-30 18:22 UTC] tunix at raptiye dot org
Description:
------------
I type

<?php echo date("l"); ?>

into an empty php file and then run it in command line prompt, and it prints this error message:

Fatal error: date(): Timezone database is corrupt - this should *never* happen! in Command line code on line 1

If I use tr_TR.UTF-8 locale, then I can produce this error. But if I use tr_TR.ISO8859-9 or C locales, it doesn't print the error message. Although, tr_TR.ISO8859-9 and C locales return Saturday which is English. It should return "Cumartesi" (turkish).

GNU date command works fine with UTF-8 locale.

[19:07] (tunix@penguix ~)$ TZ=Europe/Istanbul LANG=tr_TR.UTF-8 date +%A
Cumartesi

Reproduce code:
---------------
[19:06] (tunix@penguix ~)$ TZ=Europe/Istanbul LANG=tr_TR.UTF-8 php -r ?date(?l?);?

Fatal error: date(): Timezone database is corrupt - this should *never* happen! in Command line code on line 1


Expected result:
----------------
It's supposed to be:

[19:06] (tunix@penguix ~)$ TZ=Europe/Istanbul LANG=tr_TR.UTF-8 php -r ?date(?l?);?

Cumartesi




Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-30 20:46 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip
 [2006-12-30 23:08 UTC] tony2001@php.net
Its is reproducible with the snapshot.
I believe this happens because of strcasecmp() (used in seek_to_tz_position()) behaving weird with tr_TR locale (I remember some similar problems in the past), using something like tolower() & memcmp() should do the trick.
 [2006-12-30 23:45 UTC] iliaa@php.net
Another option that is a bit more performance friendly is 
something like this:

http://bb.prohost.org/patch/date.txt
 [2007-01-01 13:38 UTC] tokul at users dot sourceforge dot net
Issue is not fixed in 5.2.x snapshots (200701011130). You are using locale dependent case insensitive lookups and assume locale independent case sensitivity rules. In Turkish locale 'latin small i' is not same thing as 'latin capital i'. Turks have different case sensitivity rules.

Reproduce code
(TZ='Europe/Helsinki' /usr/bin/php /path/test-locale.php):
---
<?php
var_dump(setlocale(LC_ALL,'tr_TR.UTF-8'));
var_dump(date_default_timezone_get());
var_dump(setlocale(LC_CTYPE,0));
---

Expected result:
---
string(11) "tr_TR.UTF-8"
string(15) "Europe/Helsinki"
string(11) "tr_TR.UTF-8"
---
Second line depends on default timezone setting. Make sure that you have 'i' symbol in timezone name.

Actual result (PHP 5.2.0-8 debian and PHP 5.2.1RC2-dev snapshot):
---
string(11) "tr_TR.UTF-8"

Fatal error: date_default_timezone_get(): Timezone database is corrupt - this should *never* happen! in /path/test-locale.php on line 3
---

Patch by iliaa@php.net is not correct, because it does not preserve existing LC_CTYPE value and makes all strtolower/strtoupper calls locale independent when PHP manual states that these calls are locale dependent.

Result after Iliaa's patch is applied:
---
string(11) "tr_TR.UTF-8"
string(15) "Europe/Helsinki"
string(1) "C"
---
 [2007-01-18 23:20 UTC] iliaa@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC