php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79317 opcache and setlocale issue
Submitted: 2020-02-28 12:28 UTC Modified: 2020-06-03 16:17 UTC
Votes:2
Avg. Score:3.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: j dot arnold at qaamgo dot com Assigned: cmb (profile)
Status: Closed Package: opcache
PHP Version: 7.4.3 OS: OpenSuse 15.1
Private report: No CVE-ID: None
 [2020-02-28 12:28 UTC] j dot arnold at qaamgo dot com
Description:
------------
When executing the code below with "?lang=de_DE", the first call will result in a float with comma in the concatenated string. On the second call this will result in a float with a dot.

When disabling opcache the issue is gone and it is always a comma.
Also in php 7.3 this issue does not occure.

So it seems that opcache is ignoring the setlocale.

Test script:
---------------
class Test {
    function __construct() {
        // call https://domain.tld?lang=de_DE
        // first call will result in a float with COMMA in the concatenated string
        // second call will result in a float with DOT in the concatenated string

        if ($_GET['lang']) {
            setlocale(LC_ALL, $_GET['lang'] . '.utf-8');
        }

        $z = 0.5;
        $y = $z . ' invalidate cache for this class by changing something here: v1';
        echo 'Concatenated string: ' . $y . '<br />';
        echo 'Plain Variable: ';
        echo $z;
        echo '<br />';
        exit;
    }
}

$test = new Test();

Expected result:
----------------
The float will always be with ",".


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-28 12:32 UTC] girgias@php.net
This is due to the fact that displaying floats are locale aware.
 [2020-02-28 12:42 UTC] bugreports at gmail dot com
> This is due to the fact that displaying floats are locale aware

and how does that justify different behavior with or wuthout opcache?
 [2020-02-28 12:55 UTC] j dot arnold at qaamgo dot com
> and how does that justify different behavior with or wuthout opcache?

exactly, also with opcache the first call is float is correct with a "," and the second call is incorrect with a "."
 [2020-02-28 13:19 UTC] cmb@php.net
This is due to opcode optimization, in this case OPcache produces:

ECHO string("Concatenated string: 0,5 invalidate cache for this class by changing something here: v1<br />")

This also potentially happens with PHP 7.3; it depends on
opcache.optimization_level.  Using

opcache.optimization_level=0x7FFEBF7F

(i.e. disabling bit 7) makes the code working as expected.
 [2020-02-28 13:40 UTC] j dot arnold at qaamgo dot com
-Status: Open +Status: Closed
 [2020-02-28 13:40 UTC] j dot arnold at qaamgo dot com
Thanks alot! Actually we missed the difference in optimization_level when comparing 7.3 with 7.4.
 [2020-02-29 22:44 UTC] cmb@php.net
-Status: Closed +Status: Re-Opened
 [2020-02-29 22:44 UTC] cmb@php.net
Fair enough.  However, I think this generally is a valid bug
report, so I'm re-opening.
 [2020-06-03 16:17 UTC] cmb@php.net
-Status: Re-Opened +Status: Closed -Assigned To: +Assigned To: cmb
 [2020-06-03 16:17 UTC] cmb@php.net
As of PHP 8.0.0, float to string conversion no longer depends on
the locale[1], so this ticket is resolved.

[1] <https://wiki.php.net/rfc/locale_independent_float_to_string>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Oct 21 19:01:23 2020 UTC