msphpsql: sqlsrv extension modifies the locale settings and possibly breaks other software

+## PHP Driver version or file name ExtensionVer => 5.6.1 +## SQL Server version not relevant +## Client operating system Debian 10 +## PHP version 7.1.33 +## Microsoft ODBC Driver version not relevant +## Table schema not relevant +## Problem description The PHP Extension seems to override the LC_ options. This triggered a Problem in Magento 1 Shops. All prices were printed way to high. But this is not a fault of magento. I dont think a PHP extension should modify the locale settings at all.

Testing the output of localeconv with sqlsrv enabled:

/opt/php-7.1/bin/php  -r "print_r(localeconv());"
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
        )

)

Testing the output of localeconv with sqlsrv disabled :

/opt/php-7.1/bin/php  -r "print_r(localeconv());"
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
        (
        )

)

+## Expected behavior and actual behavior

  • The extension should not modify locale config

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 1
  • Comments: 18 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@yitam Thank you 😃 it was really a problem related to pdo_sqlsrv. After setting pdo_sqlsrv.set_locale_info = 0 in my php.ini file everything works like a charm.

Sorry for the fuss. You rock 👍

Hi @marvinhinz @naitsirch

We just released 5.8.0 and please check the latest documentation concerning this issue

hi @naitsirch , you can find it here

We will discuss how / whether to make this configurable, but in order not to introduce a breaking change the default might likely be the way it is now.

It’s because the driver currently sets the application locale to the system one, which in your case is de_DE.UTF-8. In other words, the driver essentially does this:

php -r "setlocale(LC_ALL, ''); print_r(localeconv());"

@yitam but this behaviour has some very unexpected and hard to debug side effects, which breaks other code. This should not happen.

As you know, setlocale(LC_ALL, 0) can be used to retrieve the current locale settings. With sqlserv extension loaded, we get this output:

$ php -r "var_dump(setlocale(LC_ALL, 0));"
string(11) "de_DE.UTF-8"

Without the extension the output looks quite different:

$ php -r "var_dump(setlocale(LC_ALL, 0));"
string(170) "LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C"

And as @marvinhinz has already pointed out, Magento (version 1) that uses the Zend Framework’s locale component (see https://framework.zend.com/manual/1.12/en/zend.locale.functions.html) struggels with the setting done by sqlsrv extension.

Can you tell me, why the extension changes the locale settings?

HI @marvinhinz

It’s because the driver currently sets the application locale to the system one, which in your case is de_DE.UTF-8. In other words, the driver essentially does this:

php -r "setlocale(LC_ALL, ''); print_r(localeconv());"