Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85537 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92987 invoked from network); 30 Mar 2015 01:54:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Mar 2015 01:54:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.176 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.176 mail-qc0-f176.google.com Received: from [209.85.216.176] ([209.85.216.176:34024] helo=mail-qc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/70-24000-8DCA8155 for ; Sun, 29 Mar 2015 20:54:32 -0500 Received: by qcay5 with SMTP id y5so59411076qca.1 for ; Sun, 29 Mar 2015 18:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=eAaKBErvYe/zRez14igl9gOaA0PEV02YYV5uKTlBWwg=; b=VkAp3ONv4LE8Vxxk5nnk6OfgZPynlzFLImn4BKmZE8ULDstrnszlMmF22ysWjRuaEE 6Ei/nxAwhM049zrqVPkwu+xP+xLqrXfyFdYI37aDJvOVR1QRFT3l4e8Kw+4WumuCirQQ CYGmC/wCLYKZzTUmLEWsfUW4YmjzrhPjoVTjFOCXgi+HU58rysjSbvPu54Y0kpWUduCy EHk4O2VKdRuvyjadBdZ1U7pix272nXo9f6IDt4o5bG/RFOpjrVOQC+9nD5vVmMblq+Lf 1FSm3Kww00FANgVtiKwH63XUSZdOxk/aq03WgAkP0YCMxDZ/9/WE1eCiADxRPghVtliB 5OOg== MIME-Version: 1.0 X-Received: by 10.55.19.160 with SMTP id 32mr5552747qkt.24.1427680469753; Sun, 29 Mar 2015 18:54:29 -0700 (PDT) Received: by 10.96.39.195 with HTTP; Sun, 29 Mar 2015 18:54:29 -0700 (PDT) In-Reply-To: References: Date: Mon, 30 Mar 2015 08:54:29 +0700 Message-ID: To: Yasuo Ohgaki Cc: Jakub Zelenka , PHP internals list Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] JSON float number as string From: pierre.php@gmail.com (Pierre Joye) On Mon, Mar 30, 2015 at 8:25 AM, Yasuo Ohgaki wrote: > Hi all, > > On Mon, Mar 30, 2015 at 9:07 AM, Yasuo Ohgaki wrote: > >> Hi Jakub, >> >> On Mon, Mar 30, 2015 at 4:33 AM, Jakub Zelenka wrote: >> >>> I would like to add a new option to JSON for dealing with large floats. >>> The >>> use case is mainly for decoder but can be used for encoder as well. >>> >>> JSON_FLOAT_AS_STRING >>> decode: all float values will be decoded as string >>> - It's often an issue for very large float values with many fractional >>> digits that are coming from platforms that support larger float >>> representation than double. In that case the conversion is lost and there >>> is no way how to get it back (see http://bugs.php.net/68456 [pls ignore >>> my >>> initial dump comments when I didn't get the issue :)] and an example of >>> the >>> lost precision here http://3v4l.org/80iCh ). Converting the value to >>> string >>> keep the precision and resolves the problem. >>> >>> encode: all float values will be encoded as string >>> - re-using the constant for encoder makes sense if PHP creates JSON for >>> platform that support lower float type (e.g. C float) and the precision >>> loss is not acceptable >>> >>> >>> I think that this is more a bugfix as the precision is lost without any >>> way >>> how to get it back (except pre-processing json string with regular >>> expression). I would like to add it to 5.6.x if there are no objections? >>> >> >> Converting int/float to PHP native type is obvious bug. >> We must consider compatibility for released versions, so >> +1 for adding JSON_FLOAT_AS_STRING option. >> >> "int" should be fixed also. >> http://3v4l.org/95dHM >> >> So option may be JSON_SCALAR_AS_STRING or >> additional JSON_INT_AS_STRING. >> >> PHP7 should have string scalars by default. IMHO. >> > > I didn't notice this bug before. This bug make me worry that new PHP7 > type hint will create a lot of type casting bugs because even C programmer > makes this kind of design mistake... > > If it's possible, coercive STH for weak type hint mode will help to reduce > type casting bugs. IMHO. Same effects but totally unrelated topics. All functions dealing with large external numbers had the same issues, since ever. It has nothing to do with STH. Cheers, -- Pierre @pierrejoye | http://www.libgd.org