Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78610 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30582 invoked from network); 4 Nov 2014 03:13:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Nov 2014 03:13:46 -0000 Authentication-Results: pb1.pair.com header.from=jrbasso@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jrbasso@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.175 as permitted sender) X-PHP-List-Original-Sender: jrbasso@gmail.com X-Host-Fingerprint: 209.85.216.175 mail-qc0-f175.google.com Received: from [209.85.216.175] ([209.85.216.175:54355] helo=mail-qc0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/E0-24107-96448545 for ; Mon, 03 Nov 2014 22:13:45 -0500 Received: by mail-qc0-f175.google.com with SMTP id b13so11545983qcw.34 for ; Mon, 03 Nov 2014 19:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=JiwORBxUhZrBRmmLOGRah9B9jypVZYNAj6Akp47LZ4Y=; b=WGgvbGNUGzTyH1q4BWCWnGq0/JFNJCHhYcRmFavMb9E12iQu8ZaOkvGcqQrqQGGjic kRgIw7WE9gnkhllFLWsKsRsoQif3rd8uYLFDOr72fcmpFDFBwT0nlq+OYl6TP3SpfSdM kmMiAkCyriRpTu0xaD2kNHZQVSk2SGUuuKZSUZy8fE5cZD3wOHuheFVXK+ADWlYDfDn4 GQ7yTLNpRmn8/anfQt5m7UkHOV+n27tgya8SdixibHiOm9ZHmmKExiKFm2YE6sghixSW Wuwy2hpIrNLv2YUscKMmVQz2yJo+fQ2a2ooO4FNO8M8dyJoidtFtEPfaRa8AQN4l/E3w d/vg== MIME-Version: 1.0 X-Received: by 10.224.3.134 with SMTP id 6mr6322513qan.87.1415070822380; Mon, 03 Nov 2014 19:13:42 -0800 (PST) Received: by 10.140.28.181 with HTTP; Mon, 3 Nov 2014 19:13:42 -0800 (PST) Date: Mon, 3 Nov 2014 22:13:42 -0500 Message-ID: To: PHP Internals Content-Type: multipart/alternative; boundary=001a11c25318b346f30506ffd9bf Subject: Add a new flag for json_encode From: jrbasso@gmail.com (Juan Basso) --001a11c25318b346f30506ffd9bf Content-Type: text/plain; charset=UTF-8 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 --001a11c25318b346f30506ffd9bf--