Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85647 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44299 invoked from network); 1 Apr 2015 18:45:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Apr 2015 18:45:08 -0000 Authentication-Results: pb1.pair.com header.from=jakub.php@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jakub.php@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.174 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.213.174 mail-ig0-f174.google.com Received: from [209.85.213.174] ([209.85.213.174:35560] helo=mail-ig0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 27/B3-21906-0BC3C155 for ; Wed, 01 Apr 2015 13:45:05 -0500 Received: by igcau2 with SMTP id au2so56561819igc.0 for ; Wed, 01 Apr 2015 11:45: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=X/cFmFBpa2yIoZQcQz1U57Jpp9hMUreOafDgXL36mx0=; b=s17L4AiCi+T8AWZMR/wcDLSCBX55ThjWXdF2ZGnmgjxYd1GqJB5DHxOYJCiL+dlTej f8V0Xw8SLnqctRAGCui2Y1CNrqpzm2NOepxtedli9J1ByZZ6k1Y1E3PqsR/zQ5rpFuJO ZPtkfQ3sjhTR9Y3K0SRX1d/TIQ1O/3Ex+udq/+8A1dH8hoK/nokO3qJAnrqeBkolwU5H M8QGc7n4iK6IYLJZXaYbAjDrqjpsZGH4RpyvRoez80y+gbMuH8pgtsHSZ+iRi/P5wDIv u0U8LPpFSCLZnkkAIgIoa4epABmH0YwqRZHZYRTNVkGzrOMrV1Be46KnOAOaRMmRZYVH oPKQ== MIME-Version: 1.0 X-Received: by 10.50.6.4 with SMTP id w4mr14523005igw.36.1427913901426; Wed, 01 Apr 2015 11:45:01 -0700 (PDT) Sender: jakub.php@gmail.com Received: by 10.107.39.18 with HTTP; Wed, 1 Apr 2015 11:45:01 -0700 (PDT) In-Reply-To: <551B9704.4030302@gmail.com> References: <551B9704.4030302@gmail.com> Date: Wed, 1 Apr 2015 19:45:01 +0100 X-Google-Sender-Auth: v8wsE7udwIMFG_TRD7fpZpWZNM0 Message-ID: To: Stanislav Malyshev Cc: PHP internals list Content-Type: multipart/alternative; boundary=047d7bdc1686dd4d4f0512ae1cfd Subject: Re: [PHP-DEV] JSON float number as string From: bukka@php.net (Jakub Zelenka) --047d7bdc1686dd4d4f0512ae1cfd Content-Type: text/plain; charset=UTF-8 Hi Stas On Wed, Apr 1, 2015 at 7:58 AM, Stanislav Malyshev wrote: > > > > 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 > > Here I'm not sure it makes much sense though. If it's float, it should > be float. It's valid JSON, so if the receiving side can not handle it, > it's their issue which they have to fix in their decoding. Just changing > the types of data when encoding JSON does not sound like a good idea. > Especially given that the reader may be some library like Java's > Jackson, where types are very important. Of course, we could add tons of > options like INT_AS_STRING, OBJECT_AS_STRING, etc. but I don't think > this is what json encoder should be doing. > > The encoding was just about re-using it. I wouldn't probably propose such constant if it was just for encoding (the main purpose is decoding though). I just thought that it could be a good idea to have some usage for encoder if it's added. It seemed to me better than just ignore it completely for encoder. What do you think? > > I think that this is more a bugfix as the precision is lost without any > way > > I don't see how it is a bugfix. Representing floats is imprecise, it is > known and not a bug. json_encode now produces completely valid > representation of the data, so no bug there either. I don't think > changing value types on encoding is a good idea. > > I didn't mean it for json_encode ( apology for that as it might have seemed that is related just to json_encode). I meant it just as "a sort of" bug for json_decode as we loose information without giving user any way how to prevent it or at least some note in documentation about that. Cheers Jakub --047d7bdc1686dd4d4f0512ae1cfd--