Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85763 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89829 invoked from network); 10 Apr 2015 00:30:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Apr 2015 00:30:24 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.52 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.216.52 mail-vn0-f52.google.com Received: from [209.85.216.52] ([209.85.216.52:40793] helo=mail-vn0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E6/20-22538-D9917255 for ; Thu, 09 Apr 2015 20:30:22 -0400 Received: by vnbg62 with SMTP id g62so1041905vnb.7 for ; Thu, 09 Apr 2015 17:30:19 -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:from:date:message-id :subject:to:cc:content-type; bh=F+CDwOROx/2QtNa1XH/ng9qh8i+114wN07ecrYqBQg0=; b=lzOJ+nJLHGK/6Ou9Saoa4+SBkcUlTzobNAKgud6eJ5Ky1vqBV47ln0vMnTWmhPggMC FBMlDMwf06qYWzCp60M0mpx8jaO49xukRE6ex/jITknmoi5YaIoeum2ItPvbqvWjQ8TF TxOV3sB/vIwrY7h1BLPe4FA/p0480CT6GL3Ja2vQNMbR6HS9Xe3rpquPXwbCGPZQLAl7 GOesMRHTUJunx/8IEvw/nCJ0rMxNalbhZ+wfHF/QPk/7XtmMcda5TdPyUYQd8HKsT4qF mNLPyfDtOMuPlsyXWB9+9o9ILWBBR8y5ViRX6E2FtMnbXvbPP64AU825cTovRpVT7LMf fGYg== X-Received: by 10.60.37.73 with SMTP id w9mr29286447oej.49.1428625818931; Thu, 09 Apr 2015 17:30:18 -0700 (PDT) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.202.104.196 with HTTP; Thu, 9 Apr 2015 17:29:38 -0700 (PDT) In-Reply-To: References: Date: Fri, 10 Apr 2015 09:29:38 +0900 X-Google-Sender-Auth: GUtBjSe08_7gbljr795pjJl17b0 Message-ID: To: Jakub Zelenka Cc: PHP internals list Content-Type: multipart/alternative; boundary=089e013cc2d6746c89051353de8a Subject: Re: [PHP-DEV] JSON float number as string From: yohgaki@ohgaki.net (Yasuo Ohgaki) --089e013cc2d6746c89051353de8a Content-Type: text/plain; charset=UTF-8 Hi Jakub, On Mon, Mar 30, 2015 at 4:33 AM, Jakub Zelenka wrote: > I would like to add a new option to JSON for dealing with large floats. The > use case is mainly for decoder but can be used for encoder as well. > > JSON_FLOAT_AS_STRING > decode: all float values will be decoded as string > - It's often an issue for very large float values with many fractional > digits that are coming from platforms that support larger float > representation than double. In that case the conversion is lost and there > is no way how to get it back (see http://bugs.php.net/68456 [pls ignore my > initial dump comments when I didn't get the issue :)] and an example of the > lost precision here http://3v4l.org/80iCh ). Converting the value to > string > keep the precision and resolves the problem. > > 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 > > > I think that this is more a bugfix as the precision is lost without any way > how to get it back (except pre-processing json string with regular > expression). I would like to add it to 5.6.x if there are no objections? > Could you add "json_encode" type hint also? Large int/float must be treated as string or GMP object (we don't have GMP float yet, though) Currently, there is no way to encode large "numeric" JSON data correctly when it is stored as string. string json_encode ( mixed $value [, int $options = 0 [, int $depth = 512 [, array $type_spec = NULL]]] ) where $type_spec specifies correct data representation. i.e. numeric, string, bool json_encode() type hint should work like Zeev's type hint. i.e. No data type conversion, but validate its content. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --089e013cc2d6746c89051353de8a--