Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78651 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69256 invoked from network); 4 Nov 2014 17:07:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 17:07:55 -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.223.180 as permitted sender) X-PHP-List-Original-Sender: jakub.php@gmail.com X-Host-Fingerprint: 209.85.223.180 mail-ie0-f180.google.com Received: from [209.85.223.180] ([209.85.223.180:44280] helo=mail-ie0-f180.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 75/BA-06676-AE709545 for ; Tue, 04 Nov 2014 12:07:54 -0500 Received: by mail-ie0-f180.google.com with SMTP id y20so7699446ier.25 for ; Tue, 04 Nov 2014 09:07:51 -0800 (PST) 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=hF9UE3fygRsjBS6CrZxEoRAqT5HVLBH5QGN0uOwHJh8=; b=uIPFtpBJM7PG3DiUahQn5OGCM1hF24+DJM8Rr6ZvtyjHSVpN7DsTFOyGdqlBfmUVh+ H17nZByIqV7chPo/ee9brUPV6kBfjJr1+AqB8tDsC2eaZQVVSstYk38q1UYLiJnCMRUB SHaSBA3gjUi0adOzXksv3raa5BTLHUCjv6hqUrlg3vP5ivmAowzKAyL9vAnQWVQO3VDR +OrHpVAHZLrsdXmnkr4S9kRJ9woGBeWiEsBN7zzf7iPlRp8kw++RDz1wJUiGxX9sTh0O hZpjcq/32nnom6MeCstS3/vPWv/OAOGGaWdOt58gBNOoqyahVqZQvvaeMTd7lwsgiMU2 c/WQ== MIME-Version: 1.0 X-Received: by 10.107.130.218 with SMTP id m87mr55725109ioi.8.1415120871475; Tue, 04 Nov 2014 09:07:51 -0800 (PST) Sender: jakub.php@gmail.com Received: by 10.107.11.217 with HTTP; Tue, 4 Nov 2014 09:07:51 -0800 (PST) In-Reply-To: References: Date: Tue, 4 Nov 2014 17:07:51 +0000 X-Google-Sender-Auth: uYnzZzj7FZkIGUm8qyIKV9PDyDM Message-ID: To: Ferenc Kovacs Cc: Juan Basso , PHP Internals Content-Type: multipart/alternative; boundary=001a113f7ebadbe63c05070b80f3 Subject: Re: [PHP-DEV] Add a new flag for json_encode From: bukka@php.net (Jakub Zelenka) --001a113f7ebadbe63c05070b80f3 Content-Type: text/plain; charset=UTF-8 On Tue, Nov 4, 2014 at 2:57 PM, Ferenc Kovacs wrote: > On Tue, Nov 4, 2014 at 4:13 AM, Juan Basso wrote: > > > Hi, > > > > I opened a pull request[1] in order to solve the bug 50224[2] and it > ended > > creating this pull request to add a new flag called > > JSON_PRESERVE_FRACTIONAL_PART on json_encode function. This flag will > make > > the json encode to output float number always with decimal part, even > when > > it is 0. > > > > Currently if you try to convert 10.0 using json_encode it outputs 10. It > > means if you decode it it will give an integer instead a float. In PHP > > words, json_decode(json_encode(10.0)) !== 10.0. > > > > After some researches and discussions it is not considered a bug because > > JSON specs treat integer and floats as number. Looking how other > languages > > treat this encoding I could find it: > > - C (using lib jansson) and Ruby the output contains the decimal portion; > > - Python and Javascript outputs without the decimal portion. > > > > So it is kind of common to have different behaviors since JSON specs > define > > it as just number. The idea of the new flag is allow PHP to behave the > both > > ways. > > > > In the pull request Stanislav Malyshev suggested to merge it in the 5.6, > > but just want to see if someone else has any objection. Ferenc Kovacs > > and Jakub Zelenka also are in favor of merging on 5.6. > > Jakub completed suggesting to have this option enabled by default on PHP > 7. > > > > Anyone has any objection on merging it on 5.6? Some comments about > enabling > > it by default in 7? > > > > As a side note, with the pull request the encode of floats are about 20% > > faster, even after the flag check. This improvement just affect float > > encoding and has no impact on the other types. > > > > [1] https://github.com/php/php-src/pull/642 > > [2] https://bugs.php.net/bug.php?id=50224 > > > > > > Thanks, > > Juan Basso > > > > Hi, > > just a slight correction: > as far as I can tell, Jakus was ok with the general idea and even with > turning this into the default, but he stated that it should only happen in > a major version (as it would cause a slight BC, maybe this could cause > problems for some people who are expecting the zeroes to be truncated from > integer values) and he also stated that he thinks that there is no reason > for a hurry to have this in a micro release, so this could wait until 7.0. > > Hey, Yeah exactly! I would really like to see it as default in the next major as it is a useful feature. However I don't like adding new flag. The reason for that is that it becomes useless after 7 is realesed. It would be useful only for >5.6.3 and <7.0 though. The only use case in PHP 7 would be just to disable the flag but that won't be very nice and completely different than other json constant usage It means doing something like $options & ~JSON_PRESERVE_FRACTIONAL_PART ... It's a bit messy IMHO. Think that it would be much better to wait till 7 with this feature. Cheers Jakub --001a113f7ebadbe63c05070b80f3--