Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87329 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39743 invoked from network); 27 Jul 2015 20:24:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jul 2015 20:24:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-ig0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:33716] helo=mail-ig0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 34/10-33169-46396B55 for ; Mon, 27 Jul 2015 16:24:04 -0400 Received: by igbpg9 with SMTP id pg9so108556037igb.0 for ; Mon, 27 Jul 2015 13:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=PA8dizYE9ZLEjPYjaWYrUyF31Q88rIuaR9FBAMoljGM=; b=kvhAOjwTfZfrgcXmUbFvLgHRKeBuF9iGYbDohgTzDTg4o32sPOtabLR+NogQCV7kXN 8qXCaoPCP20aMvrcNO9Q/Hz2pvUQAUB0P4H4VPPfPfolr2ZHJ/YGhQ99VMQXIORM3mmh CBpCk6oq+1+NJyIVpCkJUfdPU0gCWW4WbKsneG5e9+sER2lskukaic8oirU1yFh53+xf JV2hPUTMwM+/wvWtija6ip+jv9NxKk4hmlCU6E2EKugpriRZ3Aaby51v/AHJua0dN+03 u9cH8Cs8+l3XRKYi2i7pWXBbyYhmZuU+OdmLIcB+yOwebLTvlIRMizIFcIbVwACYs6fH iZ7Q== MIME-Version: 1.0 X-Received: by 10.50.111.231 with SMTP id il7mr6343635igb.23.1438028641769; Mon, 27 Jul 2015 13:24:01 -0700 (PDT) Sender: jakub.php@gmail.com Received: by 10.107.20.68 with HTTP; Mon, 27 Jul 2015 13:24:01 -0700 (PDT) In-Reply-To: References: Date: Mon, 27 Jul 2015 21:24:01 +0100 X-Google-Sender-Auth: 6ndxsjGHGbdbVoKItMf_kEwxpgc Message-ID: To: Yasuo Ohgaki Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=047d7b4142c85e9eff051be122d7 Subject: Re: [PHP-DEV] json_decode/encode should return full precision values by default From: bukka@php.net (Jakub Zelenka) --047d7b4142c85e9eff051be122d7 Content-Type: text/plain; charset=UTF-8 Hi Yasuo, On Sun, Jul 26, 2015 at 9:20 PM, Yasuo Ohgaki wrote: > Hi Jakub, > > On Mon, Jul 27, 2015 at 3:32 AM, Jakub Zelenka wrote: > >> I don't think that this is a bug. Your example is also completely >> unrelated to json because the place when the value is rounded is var_dump >> where it's based on ini precision. You would get the same values with >> json_encode but it's only because it uses the same ini ( precision ). >> Basically it has nothing to do with json_decode. >> > > OK. Better example. > > [yohgaki@dev PHP-master]$ ./php-bin > $j = '{ "v": 0.1234567890123456789 }'; > var_dump(json_encode(json_decode($j))); > ini_set('precision', 20); > var_dump(json_encode(json_decode($j))); > ?> > > > string(22) "{"v":0.12345678901235}" > string(28) "{"v":0.12345678901234567737}" > Yeah you will loose precision. That's just the fact that double can't contain such a big precision. This is of course the same for serialize and unserialize. See this example: http://3v4l.org/nb3mE The only difference is that that it is using different ini but you can still change it if you want. The precision lost is the same if the values are the same though. > > I see that that the bug report you created ( >> https://bugs.php.net/bug.php?id=70137 ) is actually about using >> serialize.precision instead of precision in json_encode . I agree that >> using 'precision' ini is not the best solution. However I don't think that >> start suddenly using serialize.precision is a good idea. First of all it's >> a big BC break that will be quite difficult to find (There is no way this >> should go to the point release because this is changing the generated >> json). Also the json encode usage is much wider than serialization. There >> might be use cases when you don't care about maximal precision and you >> prefer to save some space. Imagine that you are transferring lots of float >> numbers. Then it will result in increasing of the transfer size. It would >> be great if the new ini was used when it was introduced but I'm afraid that >> changing that now is not a good idea >> >> I think that due to BC break, this shouldn't be changed. If you really >> want a bigger precision, you can do ini_set('precision', 30) before >> json_encode and then set it back. It means that this not a bug because you >> can still change it if you want. That means that we can't change before PHP >> 8 or whatever comes after 7... :) >> > > Same argument could be done for serialize, but it's changed to keep > more precise value. Manual recommend json_decode/encode for data > serialization also. > > Warning > Do not pass untrusted user input to unserialize(). Unserialization can > result in code being loaded and executed due to object instantiation and > autoloading, and a malicious user may be able to exploit this. Use a safe, > standard data interchange format such as JSON (via json_decode() and > json_encode()) if you need to pass serialized data to the user. > http://jp2.php.net/manual/en/function.unserialize.php > > It does not make sense having different serialization for float. > Losing effective precision is design bug. IMHO. > As I said I think that using preicision constant was unfortunate but start using serialize_precision is not a win IMHO. Using serialize and json_encoding are not the same thing. In any case this is not a bug, it's just an unfortunate decision and we should not definitely change it in a bug fixing release. It's a BC break. Maybe if we do an RFC, it could be considered for 7.1 but voters will need to agree that. I'd imagine 3 voting choices: * keep it as it is (use precision) * use serialize_precision * introduce new json_precision > > Currently users cannot handle even Google Map JSON data correctly by > default. > Fixing this is just a matter of using serialize.precision. If users need > larger setting > than 17 for whatever reason, they may do ini_set('serialize.precision', > 30) and the > rest of codes are unaffected. > you can still do ini_set('pricision', 17) resp. ini_set('pricision', 30). > > > BTW, larger precision setting does not mean precise, but current behavior > definitely lose effective values. Those who don't care for precise data > handling > wouldn't care for more precise data handling, do they? > > yeah but mind that the side effect of rising precision is an increasing size of the json_encoded data which is not what everyone is happy with... Cheers Jakub --047d7b4142c85e9eff051be122d7--