Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:69458 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47303 invoked from network); 2 Oct 2013 17:26:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Oct 2013 17:26:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.41 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-la0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:36402] helo=mail-la0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/9B-23255-9375C425 for ; Wed, 02 Oct 2013 13:26:18 -0400 Received: by mail-la0-f41.google.com with SMTP id ec20so957996lab.0 for ; Wed, 02 Oct 2013 10:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=Wx7BRo85JwecUn1RbQupdIswbKUcjoL3GQ1rsqSimoY=; b=B+fU8u/eaqgOpRQMoRxzb51WHLmVqMPX4tU4Pm0ZgOXF8FSJ/jDu7IdEI+VwUDPBE8 9PF1Kde7MaueodJCZrHuFS57O/qJaXC20H/KG7Auj6J3zDAPs7z31XAfeXwvABYBZYHV BP6DsshYj8wDSe29rjRhqCSKPuKDaRkNtIcWOeSeNtVPGHS3DVuB8b0M3Pe1PB+oW8M9 X/uf2l9mTQUksltDxtFOkXeH4BXZAFEOOO+4KqRV+2JI/QWEPY+9jp20XNF/k8EM/9Ck O4wbNE3KNC8khQPjj+c/1snQf8+Xv2U/e1rW2590huJh2F7X8r1gQ96t/q24EYTMtBVd hIUA== MIME-Version: 1.0 X-Received: by 10.152.116.7 with SMTP id js7mr2840594lab.11.1380734774570; Wed, 02 Oct 2013 10:26:14 -0700 (PDT) Received: by 10.112.133.202 with HTTP; Wed, 2 Oct 2013 10:26:14 -0700 (PDT) Date: Wed, 2 Oct 2013 19:26:14 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=001a11c2672ac4740104e7c55d73 Subject: Locale-independent double-to-string cast From: nikita.ppv@gmail.com (Nikita Popov) --001a11c2672ac4740104e7c55d73 Content-Type: text/plain; charset=ISO-8859-1 Hi internals! I'd like to change our double-to-string casting behavior to be locale-independent and would appreciate some opinions as to whether you consider this feasible. So, first off, this is how PHP currently behaves: raw($value); if (false !== $locale) { setlocale(LC_NUMERIC, $locale); } In this case (just like with MySQL) you will also not just emit wrong code, but it can end up being working code with totally different semantics (as "," is usually a function argument separator). These are just three random examples I came up with, but I've seen this issue a lot of times. The insidious thing about it is that, with very high probability, you will not notice this issue during development (because you don't use locales), it will only turn up later. So, my suggestion is to change the (string) cast to always use "." as the decimal separator, independent of locale. The patch for this is very simple, just need to change a few occurrences of "%.*G" to "%.*H". I think not having the locale-dependent output won't be much of a loss for anyone, because if you need to actually localize the output of your numbers, it is very likely that just replacing the decimal separator is not enough (you will at least want to have a thousands-separator as well, i.e. you want to use number_format). So, thoughts? Nikita (Sorry for the long rant) --001a11c2672ac4740104e7c55d73--