Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103671 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50622 invoked from network); 2 Jan 2019 22:58:45 -0000 Received: from unknown (HELO mail-ed1-f44.google.com) (209.85.208.44) by pb1.pair.com with SMTP; 2 Jan 2019 22:58:45 -0000 Received: by mail-ed1-f44.google.com with SMTP id h15so27112360edb.4 for ; Wed, 02 Jan 2019 11:31:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:content-transfer-encoding:date:from:to:cc:subject :in-reply-to:references:message-id:user-agent; bh=8Z2Ob8FODO2K7sy0SDzfaeKo1KouqWKywk8t+QwQWlQ=; b=ocd49ThP61BzOqcimrWZw5ViZbfmzMNQBV4e7UsRHs3cfKP2pLeOxc5lbnRCu5ujQU 7INeOjwZ1d3aEpg+b0s325fXZ94vJncy7CYvdv6CDKDzJe+eIDFltm6HIPXGKYueLysK OI5FrjcJHDrOrHCAnYuuO/7c226u1g7wlu8xXKoyvdrQIcQOgIxn+rufRmsYoOw8kf9M 28u6WhcZyNn2OsqGYo1pMEKe4MqmUkyyJA+3isMMR0jdO6V6Ncg+jplI14VlcP53prsX BzE/y9Iy2U0oCaWsMp2XDJ7Cj4/dVujfmBRpsdngp9Pui4feaa1V0bPpJ2rMLTAgSzrQ gfxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding:date:from :to:cc:subject:in-reply-to:references:message-id:user-agent; bh=8Z2Ob8FODO2K7sy0SDzfaeKo1KouqWKywk8t+QwQWlQ=; b=BwV14EH3cnJl9cOutroM4/tzSFocL8QP4Q4sz2n1xIBXH5XPAF1k9OZ/TkXsfsBwtS ECdCxUXCtL/ylbLsa7iz1Rfot8akyqTgraajQQwgZ/gIeqXwLmXHjVkfT/BNvztj44wk Xk/PEv9vG0GUzMVm72/KVpN8NS7oFENcttrjJPHnS87TBi9/766G2Z1kTmpgGPvn5rL2 sS+CfYMMwghsAXRjDdafa6GFdy2b3m7JNyoOp414rkl+KPFQj58CUmAySjIL+I94z8kB jcix/jgymVphCqbN1FXGq91ZQDz73az7cPdWuOOa/e12toLbA0kLN3PQE1qR6itvkJo7 vDeQ== X-Gm-Message-State: AA+aEWZSGykbBr/mD0w83uSeoJRSD9QJQStN+5XjL21TvCYeYBy3ZnRw 1xnDFHACpCn662QaqvIw9D9o+woc X-Google-Smtp-Source: AFSGD/UnaOxrwGCqR0dopcnZIw1Bt4HLAf6lfIEfdYwkfKPr9idXekNfVjTxXbs4ucWwFcLBUW0pag== X-Received: by 2002:a50:c252:: with SMTP id t18mr39641118edf.57.1546457486711; Wed, 02 Jan 2019 11:31:26 -0800 (PST) Received: from k-piste.fi (k-piste.fi. [178.62.210.197]) by smtp.gmail.com with ESMTPSA id r1sm19328070eds.1.2019.01.02.11.31.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jan 2019 11:31:25 -0800 (PST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Wed, 02 Jan 2019 21:31:24 +0200 To: Zeev Suraski Cc: PHP internals In-Reply-To: References: <94f5feb8-6589-3a0a-2849-7679cec1858c@gmx.de> Message-ID: X-Sender: lauri.kentta@gmail.com User-Agent: Roundcube Webmail/1.3.8 Subject: Re: [PHP-DEV] Inconsistent float to string vs. string to floatcasting From: lauri.kentta@gmail.com (=?UTF-8?Q?Lauri_Kentt=C3=A4?=) On 2019-01-02 19:22, Zeev Suraski wrote: > 1. I'm not sure what you mean "not many people use this"? People don't > convert floats to strings? People don't format their floats using setlocale + echo. People use things like sprintf and number_format to get the right number of decimals, and many use number_format or even str_replace to change the decimal separator because setlocale has weird side effects (like the one being discussed). On 2019-01-02 19:22, Zeev Suraski wrote: > 3. I view a UX change as a big deal. As we should in a language that > is > very commonly used to create UI. Then what about existing UI bugs? Thanks to this discussion, I found exactly one instance of setlocale in my whole PHP code base (used to format a printf nicely), and I also found a bug where "stringparam=$x" was ill-formatted because of this and produced a visible error in a generated image (although not critical and thus unnoticed until now). I was certainly not relying on this behaviour. It was just bad luck that the output (at least when I saw it – don't know about other users!) was ”good enough” that I didn't notice the bug. On 2019-01-02 19:22, Zeev Suraski wrote: > 4. This could effect not only UX, but also integration code. You could > have PHP output feeding into something else - and suddenly, the format > breaks. With the fix HAVING to be in the other side, no less. It's reasonable to expect that a float (with known range) is a valid number in most programming contexts such as CSS (width: px) or HTML (input type=number value=) or JavaScript (var width = ). Using number_format to fix these would feel almost as bad as using number_format before every arithmetic operation. Because of this behaviour, using setlocale will break many libraries which output floating-point values in any other context than user-visible text. On 2019-01-02 19:22, Zeev Suraski wrote: > With the fix HAVING to be in the other side, no less. How so? If you send floats, you can format them yourself (and you certainly should, if they are locale-dependent!). If you receive floats, you can parse them yourself. No need to change ”the other side”. -- Lauri Kenttä