php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #26052 setlocale() does not work under FreeBSD
Submitted: 2003-10-31 06:16 UTC Modified: 2004-09-16 16:00 UTC
From: nicos at worldakt dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.3.3 OS: FreeBSD
Private report: No CVE-ID: None
 [2003-10-31 06:16 UTC] nicos at worldakt dot com
Description:
------------
setlocale() fails under FreeBSD 4.8:

[Fri Oct 31 - 17:56:28 - root /httpd/php-4.3.3]# cat configure.log | grep locale
checking for locale.h... (cached) yes
checking for setlocale... (cached) yes
checking for localeconv... (cached) yes
[Fri Oct 31 - 17:56:45 - root /httpd/php-4.3.3]# 

In fact, setlocale returns FALSE but no E_WARNING or anything.

After looking in ext/standard/string.c it looks like it can happen when HAVE_SETLOCALE is not defined...

But HAVE_SETLOCALE is defined.

Another solution is that, setlocale() call fails:

retval = setlocale (cat, loc);

We've got an if (retval) { } but no else... 
According to freebsd's man, setlocale returns NULL on failure. 

I added:
else {
     /* setlocale failed */
     efree(args);
     php_error_docref(NULL TSRMLS_CC, E_WARNING, "setlocale failed!");
     RETURN_FALSE;
}

And I get the E_WARNING, so it means setlocale() call failed, but why ? the same scripts works fine under linux but not under freebsd4.8. 

After looking in /usr/share/locale, we have:

/usr/share/locale/fr_FR.ISO8859-1:
LC_COLLATE      LC_CTYPE        LC_MESSAGES     LC_MONETARY     LC_NUMERIC      LC_TIME

/usr/share/locale/fr_FR.ISO8859-15:
LC_COLLATE      LC_CTYPE        LC_MESSAGES     LC_MONETARY     LC_NUMERIC      LC_TIME

/usr/share/locale/fr_FR.ISO_8859-1:
LC_COLLATE      LC_CTYPE        LC_MESSAGES     LC_MONETARY     LC_NUMERIC      LC_TIME

/usr/share/locale/fr_FR.ISO_8859-15:
LC_COLLATE      LC_CTYPE        LC_MESSAGES     LC_MONETARY     LC_NUMERIC      LC_TIME

so it should work.

If I have change fr_FR to fr_FR.ISO_8859-1 in the setlocale call, the script works fine, isn't setlocale() supposed to use default charset which is ISO_8859-1 ? In any case the documentation does not mention that we have to add the charset under FreeBSD...

Reproduce code:
---------------
setlocale(LC_TIME, "fr_FR");
echo strftime("%B %Y",$timestamp);


Expected result:
----------------
TRUE
Octobre 2003

Actual result:
--------------
FALSE
October 2003

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-31 08:04 UTC] sniper@php.net
No bug here. different OSes have different naming schemes for locales. Nothing we can/should do about that.
Reclassified as documentation issue. (there's already note for Windows about the same thing)


 [2004-09-16 16:00 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"Different systems have different naming schemes for locales."
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 13:01:33 2025 UTC