php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28057 nl_langinfo returns wrong data for de_DE
Submitted: 2004-04-19 14:28 UTC Modified: 2005-02-11 01:00 UTC
Votes:3
Avg. Score:3.3 ± 1.2
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bublavas at ecetra dot com Assigned:
Status: No Feedback Package: Strings related
PHP Version: 4.3.6 OS: 2.4.21-9.EL GNU/Linux
Private report: No CVE-ID: None
 [2004-04-19 14:28 UTC] bublavas at ecetra dot com
Description:
------------
nl_langinfo returns wrong values for THOUSEP and RADIXCHAR after setting the locale to 'de_DE'. Using localeconv() returns the same wrong values.

An equivalent C program returns correct results.

PHP 4.3.4 returns the same results as 4.3.6; executing the script from the command line vs. using HTTP (Apache 2.0.48) makes no difference as well.

Reproduce code:
---------------
if ( setlocale(LC_ALL, 'de_DE') )
{
    echo "thousands separator: ", nl_langinfo(THOUSEP), "\n";
    echo "decimal point: ", nl_langinfo(RADIXCHAR), "\n";
}
else
{
    echo "cannot set locale to de_DE", "\n";
}


Expected result:
----------------
thousands separator: .
decimal point: ,

Actual result:
--------------
thousands separator:
decimal point: .

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-19 15:13 UTC] wez@php.net
No, the problem is in setlocale().
When you set LC_NUMERIC or LC_ALL and the decimal point is not '.', then LC_NUMERIC is set back to "C" again.
This hack is required for serialize() when handling floating point numbers.
 [2004-04-19 15:38 UTC] bublavas at ecetra dot com
Hmm, shouldn't this hack be in serialize() then? Do you know a  workaround that I can use?
 [2004-04-23 11:42 UTC] phpdev at martinsojka dot de
Bugfix @ http://www.martinsojka.de/patches/php-4.3.6-bug28057.patch

This one is of the "works for me" kind. It needs at least a check for ENOMEM where strdup() is used, but I don't know enough of PHP's internal error handling to add that quickly.

Test:

<?php
echo "Default locale:\n";
echo "serialized 0.25: \"", serialize(2.5e-1), "\", ";
echo "thousands separator: \"", nl_langinfo(THOUSEP), "\", ";
echo "decimal point: \"", nl_langinfo(RADIXCHAR), "\"\n";
if ( setlocale(LC_ALL, 'de_DE') )
{
    echo "de_DE locale:\n";
    echo "BEFORE serialize, ";
    echo "thousands separator: \"", nl_langinfo(THOUSEP), "\", ";
    echo "decimal point: \"", nl_langinfo(RADIXCHAR), "\"\n";
    echo "serialized 0.25: \"", serialize(2.5e-1), "\", ";
    echo "thousands separator: \"", nl_langinfo(THOUSEP), "\", ";
    echo "decimal point: \"", nl_langinfo(RADIXCHAR), "\"\n";
}
else
{
    echo "cannot set locale to de_DE", "\n";
}
?>

Expected output:

Default locale:
serialized 0.25: "d:0.25;", thousands separator: "", decimal point: "."
de_DE locale:
BEFORE serialize, thousands separator: ".", decimal point: ","
serialized 0.25: "d:0.25;", thousands separator: ".", decimal point: ","

... or:

Default locale:
serialized 0.25: "d:0.25;", thousands separator: "", decimal point: "."
cannot set locale to de_DE
 [2005-02-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 30 14:01:28 2024 UTC