Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78643 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48682 invoked from network); 4 Nov 2014 14:57:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 14:57:32 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.44 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.192.44 mail-qg0-f44.google.com Received: from [209.85.192.44] ([209.85.192.44:38727] helo=mail-qg0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8B/97-06676-959E8545 for ; Tue, 04 Nov 2014 09:57:30 -0500 Received: by mail-qg0-f44.google.com with SMTP id q107so10637391qgd.31 for ; Tue, 04 Nov 2014 06:57:26 -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=goSfUE8HORndAUbeQMNHeOZPh9g9sAoIGp/cZ5jJ/lk=; b=sBsTUlf80xHwjVOnLycR7D/AGwbT03Kf/BEmwmKCv7VbyALAIY4eS9qSxWRq+YoQ79 EdLlpJguNdVu3ajuG1tDJZ0daVBg7hPCNf6URArAEktxH50Jf6bT94Ksv1M2G06vEQCw DVkvLD42tYEzgle2xz5Smtx08urgnGrV/xmnrvPt/ZX1ikFKpxTgbdS783uAU19VvjG0 OeoIUpSPUIy5Mbhg9wW4eiOMTjQGsRLLYREiKeDiuM8jeqlsjec3/Yj6/lt9kmQwgoDE aqy83RRQLAOgpAljL+TOpwIvNH2A8kuTw0NLp4YA9/HSUJSq4nSrZbCh0YGxYAVo261G izSg== MIME-Version: 1.0 X-Received: by 10.140.34.208 with SMTP id l74mr71523257qgl.99.1415113041928; Tue, 04 Nov 2014 06:57:21 -0800 (PST) Received: by 10.140.93.47 with HTTP; Tue, 4 Nov 2014 06:57:21 -0800 (PST) In-Reply-To: References: Date: Tue, 4 Nov 2014 15:57:21 +0100 Message-ID: To: Juan Basso , Jakub Zelenka Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c102642e75e4050709ae26 Subject: Re: [PHP-DEV] Add a new flag for json_encode From: tyra3l@gmail.com (Ferenc Kovacs) --001a11c102642e75e4050709ae26 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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 ende= d > creating this pull request to add a new flag called > JSON_PRESERVE_FRACTIONAL_PART on json_encode function. This flag will mak= e > the json encode to output float number always with decimal part, even whe= n > 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)) !=3D=3D 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 language= s > 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 defi= ne > it as just number. The idea of the new flag is allow PHP to behave the bo= th > 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 enabli= ng > 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=3D50224 > > > 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. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu --001a11c102642e75e4050709ae26--