Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:103640 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 82063 invoked from network); 26 Dec 2018 19:36:33 -0000 Received: from unknown (HELO mail-ot1-f48.google.com) (209.85.210.48) by pb1.pair.com with SMTP; 26 Dec 2018 19:36:33 -0000 Received: by mail-ot1-f48.google.com with SMTP id n8so14335258otl.6 for ; Wed, 26 Dec 2018 08:07:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=huFGF4AsWKkYSCdjXd7o3+xbxdSbSnAdvSreN6epYN0=; b=s574wTcLxunNBF94yMQVBZIdgzm8QcwFp3W6mJZafV+PvwbfyPndvyRZcUall8s43f IeB/S9B95VyZKW1Bwzw8Cdm+OuQKuuRQpSPjU4/sB66CPo1D6GAmVDWZfpw0mSkXGMWy 1neC98Zqiqk0N6W2l323yhRS9Tnb+BgfxbqJlsc1x3tSBcCjfET/N08opdLAt4ouzvDN MGazooHWyDBNSB97JH2tfJvR3wmCXZw1h5iYRUZE3h7x786GBwaXuvmmfIo+56q4grYP zE8UmFUlRtebRxKM06l+1p+QiOX173PRK5pzwxb+5Tqpcl+y3uxtIow93+jOyuBU7pPb n42g== X-Gm-Message-State: AJcUukdikdXJXfDIfCRRuDrynwdnTO1RWKy27jfStbsmznZjvmKGO2oC VyHY2nxGArTavSlfdNm5Ux1/1MSOT/8ctbUOfMQ= X-Google-Smtp-Source: ALg8bN4ULARj+b1dtg3XH4guMnBz0UfL3rGI/whNc4NZkponReIM0uyLrmHQx36+cAKf2PGkt1qKvI0BlavL9MFy0GU= X-Received: by 2002:a9d:398a:: with SMTP id y10mr14247969otb.122.1545840448132; Wed, 26 Dec 2018 08:07:28 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 Dec 2018 17:07:17 +0100 Message-ID: To: Nikita Popov Cc: "Christoph M. Becker" , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Inconsistent float to string vs. string to float casting From: kalle@php.net (Kalle Sommer Nielsen) Den ons. 26. dec. 2018 kl. 16.53 skrev Nikita Popov : > > On Wed, Dec 26, 2018 at 4:48 PM Christoph M. Becker > wrote: > > > Hi! > > > > Regarding the decimal separator (aka. decimal point), the behavior of > > casting float to string is inconsistent with casting string to float. > > While the former regards the current locale, the latter always expects a > > decimal point regardless of the locale. This breaks round-trips for > > locales which use something else than a dot as decimal separator (e.g. > > German, which uses a comma), for instance: > > > > $float = 1/3; // float(0,33333333333333) > > $string = (string) $float; // string(16) "0,33333333333333" > > $float = (float) $string; // float(0) > > > > As for me, the question is not *if*, but rather *when* and *how* this > > inconsistency should be resolved. Regarding the *when*, it seems to me > > we have to wait for the next major version, i.e. PHP 8. Regarding the > > *how* I tend to prefer the non-locale aware behavior, i.e. float to > > string conversion should always produce a decimal *point*. Users still > > can explicitly use number_format() or NumberFormatter if they wish. > > > > Thoughts? > > > > Yes, please. Locale-sensitive library functions are bad enough, but core > language behavior should *never* be locale-sensitive. > > I'm definitely in favor of making float to string casts locale-independent > in PHP 8. I'm in the same boat here. I remember we had some interesting behaviorial differences on a language level too[1] (which seems to also have maybe resurfaced after reading the newest comments). [1] https://bugs.php.net/bug.php?id=18556 -- regards, Kalle Sommer Nielsen kalle@php.net