Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79307 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38538 invoked from network); 29 Nov 2014 09:44:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Nov 2014 09:44:49 -0000 Authentication-Results: pb1.pair.com header.from=kris.craig@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kris.craig@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.47 as permitted sender) X-PHP-List-Original-Sender: kris.craig@gmail.com X-Host-Fingerprint: 209.85.218.47 mail-oi0-f47.google.com Received: from [209.85.218.47] ([209.85.218.47:62335] helo=mail-oi0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/10-36070-E8599745 for ; Sat, 29 Nov 2014 04:44:47 -0500 Received: by mail-oi0-f47.google.com with SMTP id v63so5594873oia.34 for ; Sat, 29 Nov 2014 01:44:42 -0800 (PST) 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=REByAhzB/kpWJGUhVVCNG/whKk9YEdvk2+pxl7H1KJs=; b=ayxCYP5rbHLiXI2UAsdo6tTsk14SYRV+HGmgKrspk3pUgRaq6xZZuuzfrlb2UBQGXI 2NEVRD1/G4rkAXvVY2YCyuWJ2bw3J/Sn6bXRg7l+sf7QONJaV0Wx5yRNT6ZV+8CG9jsu AeGinvjezQ27oXS6k1XahDLgiQSkNFJEjQdQFvQdl6wEg9HQ9Rp1uToPs/rT9od5dTcG yvBEF1KHlG7zFouPVOmNdVAW6cdM6WIlRjBzbd7isdRdO74MbjflGG6aj3S7d++4EAQn S5Vbj5uUk6/GRwuyq50nXNI8z9GhT8D1AEu514zvyVZsjmGXRT79T7hLdkPM/ALU/A8P FVfg== MIME-Version: 1.0 X-Received: by 10.202.183.84 with SMTP id h81mr28318067oif.19.1417254282620; Sat, 29 Nov 2014 01:44:42 -0800 (PST) Received: by 10.202.227.133 with HTTP; Sat, 29 Nov 2014 01:44:42 -0800 (PST) Received: by 10.202.227.133 with HTTP; Sat, 29 Nov 2014 01:44:42 -0800 (PST) In-Reply-To: References: Date: Sat, 29 Nov 2014 01:44:42 -0800 Message-ID: To: Juan Basso Cc: PHP internals list Content-Type: multipart/alternative; boundary=001a113cd18c1276750508fc3a73 Subject: Re: [PHP-DEV] Add a new flag for json_encode From: kris.craig@gmail.com (Kris Craig) --001a113cd18c1276750508fc3a73 Content-Type: text/plain; charset=UTF-8 On Nov 3, 2014 7:13 PM, "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 Despite some tangential disagreements regarding the default behavior, there does appear to be a general consensus with regard to the optional argument. Could you please post an RFC for this if you haven't already? Thanks! --Kris --001a113cd18c1276750508fc3a73--