PHP switches LC_NUMERIC since PHP 7 Upgrade

Hi folks!

This is my first Post here :slight_smile:
We have switched from PHP 5.6 to PHP 7.3 a few weeks ago. Most things worked fine and we are very happy to left PHP 5 behind us and can do a much better programming than before.

But actually we have a big problem. Since we changed to PHP 7.3 we found an bug we do not understand were this is coming from.

In our system we do some calculation and invoicing. In that places we often use float datatype. Normally we would excpect, that all float types got a format with a “dot” for example “1017.87”.
Now sometimes we have the bug, that the float types are with “comma” so for example “1017,87”.

In the PHP Documentation we found this part when using “setLocale”:

Warning
The locale information is maintained per process, not per thread. If you are running PHP on a multithreaded server API like IIS, HHVM or Apache on Windows, you may experience sudden changes in locale settings while a script is running, though the script itself never called setlocale() . This happens due to other scripts running in different threads of the same process at the same time, changing the process-wide locale using setlocale() .

So we checkt our whole project, were this could be a problem. But even when we switched to use only the LC_TIME instead of LC_ALL, this does happen.

Since the programm was running normally on PHP 5.6 we checked some release notes but even found something that could be the problem.

Maybe someone out here in the community can help us.

Best Regards!
TobyMaxham

Two things, where did you use setlocale? Run this to see what you are actually getting:
If you set the locale at the page level, then it will only have an effect on that specific script. If you do it from the ini file, that will handle it for the entire server.

// setlocale(LC_ALL,"US");
print_r(localeconv());

The problem is, this also seems “random”.
I created a new file “lc_test.php” and placed it outside of the project. The first time i called the script I get something like this:

Array
(
    [decimal_point] => .
    [thousands_sep] => 
    [int_curr_symbol] => 
    [currency_symbol] => 
    [mon_decimal_point] => 
    [mon_thousands_sep] => 
    [positive_sign] => 
    [negative_sign] => 
    [int_frac_digits] => 127
    [frac_digits] => 127
    [p_cs_precedes] => 127
    [p_sep_by_space] => 127
    [n_cs_precedes] => 127
    [n_sep_by_space] => 127
    [p_sign_posn] => 127
    [n_sign_posn] => 127
    [grouping] => Array
        (
        )

    [mon_grouping] => Array
        (
        )

)

But after a few page request I got this output:

Array
(
    [decimal_point] => ,
    [thousands_sep] => .
    [int_curr_symbol] => EUR 
    [currency_symbol] => €
    [mon_decimal_point] => ,
    [mon_thousands_sep] => .
    [positive_sign] => 
    [negative_sign] => -
    [int_frac_digits] => 2
    [frac_digits] => 2
    [p_cs_precedes] => 0
    [p_sep_by_space] => 1
    [n_cs_precedes] => 0
    [n_sep_by_space] => 1
    [p_sign_posn] => 1
    [n_sign_posn] => 1
    [grouping] => Array
        (
            [0] => 3
            [1] => 3
        )

    [mon_grouping] => Array
        (
            [0] => 3
            [1] => 3
        )

)

It’s around 1 Percent, but if a users hits that on invoicing or any relevant process we care about float values, we have problems.
We also use the internal php-fpm stats. When we call that page with “?json&full” than you can see some CPU information. Even this sometimes shows the CPU with “,” instead of “.”. Since this is a JSON output, everytime it hits a “,”, the JSON output became invalid.

You said “from the ini file”. How could I configure setLocale from PHP-ini File? Maybe this really could solve the problem.

Sponsor our Newsletter | Privacy Policy | Terms of Service