[RFC] Preserve Fractional Part in JSON encode

php.internals

Juan Basso

11 years ago
Good evening and merry christmas, After some discussion in a separated thread I created the RFC to discuss about the implementation of another json_encode option. The RFC can be found here: https://wiki.php.net/rfc/json_preserve_fractional_part Juan Basso

Andrew Faulds

11 years ago
> On 25 Dec 2014, at 19:32, Juan Basso <jrbasso@gmail.com> wrote: > > Good evening and merry christmas, > > After some discussion in a separated thread I created the RFC to discuss > about the implementation of another json_encode option. > > The RFC can be found here: > https://wiki.php.net/rfc/json_preserve_fractional_part > > > Juan Basso
Hi, While I can see there’s some benefit to this when dealing with poorly-written JSON parsers, I think that we definitely shouldn’t make this behaviour the default. Thanks.
-- Andrea Faulds http://ajf.me/

Ferenc Kovacs

11 years ago
On Thu, Dec 25, 2014 at 9:05 PM, Andrea Faulds <ajf@ajf.me> wrote:
> > > On 25 Dec 2014, at 19:32, Juan Basso <jrbasso@gmail.com> wrote: > > > > Good evening and merry christmas, > > > > After some discussion in a separated thread I created the RFC to discuss > > about the implementation of another json_encode option. > > > > The RFC can be found here: > > https://wiki.php.net/rfc/json_preserve_fractional_part > > > > > > Juan Basso > > Hi, > > While I can see there’s some benefit to this when dealing with > poorly-written JSON parsers, I think that we definitely shouldn’t make this > behaviour the default. >
AFAIK that is only mentioned under the future scope, so deciding about that is out-of-scope for the current RFC.
-- Ferenc Kovács @Tyr43l - http://tyrael.hu

Stas Malyshev

11 years ago
Hi!
> Good evening and merry christmas, > > After some discussion in a separated thread I created the RFC to discuss > about the implementation of another json_encode option. > > The RFC can be found here: > https://wiki.php.net/rfc/json_preserve_fractional_part
Completely makes sense for me as an option, for 5.6 and maybe even 5.5. As a default, not so sure, but this should not hold adding an option.
-- Stas Malyshev smalyshev@gmail.com

Juan Basso

11 years ago
Exactly. The idea of this RFC is just to add as a new option and not enabled by default. The idea to enable it by default was discussed before and I just added as future scope since it is not an easy decision, especially because the backward compatibility. The main goal is to have the option to choose any of the behaviors. On Thu, Dec 25, 2014 at 7:54 PM, Stanislav Malyshev <smalyshev@gmail.com> wrote:

Andrew Faulds

11 years ago
> On 25 Dec 2014, at 19:32, Juan Basso <jrbasso@gmail.com> wrote: > > The RFC can be found here: > https://wiki.php.net/rfc/json_preserve_fractional_part
Hey Juan, A further thought: is “Preserve Fractional Part” the best name? Integral floats like float(12) don’t have any fractional part, and besides, the name doesn’t tell you what it does IMO. Perhaps something like JSON_FLOAT_ADD_POINT_ZERO? It’s more literal and, I think, more obvious. Thanks.
-- Andrea Faulds http://ajf.me/

Juan Basso

11 years ago
Andrea, I am not a specialist in float numbers, but I think integral float numbers have a fractional part with value 0. JSON_FLOAT_ADD_POINT_ZERO can be confuse for regular floats with non-zero as fractional part. Seems you are going to add a point zero in a regular float with point something. Anyway, I am open to rename the constant to make it clear for everyone. I just can't find a better name than that. By the way, this name was proposed by Kevin Israel (plstand) on the PR. On Thu, Dec 25, 2014 at 9:01 PM, Andrea Faulds <ajf@ajf.me> wrote:

Juan Basso

11 years ago
Hi, Everyone has any concern on the constant name as Andrea mentioned? Should we keep or rename it? If this name is fine and there is no other concerns probably in 3 days (when completes 2 weeks) this RFC can be moved to voting, right? Thanks, Juan Basso On Thu, Dec 25, 2014 at 9:17 PM, Juan Basso <jrbasso@gmail.com> wrote:

Ferenc Kovacs

11 years ago
On Mon, Jan 5, 2015 at 5:18 AM, Juan Basso <jrbasso@gmail.com> wrote:
> Hi, > > Everyone has any concern on the constant name as Andrea mentioned? Should > we keep or rename it? If this name is fine and there is no other concerns > probably in 3 days (when completes 2 weeks) this RFC can be moved to > voting, right? > > > Thanks, > Juan Basso >
I prefer the originally proposed constant name (JSON_PRESERVE_FRACTIONAL_PART) over JSON_FLOAT_ADD_POINT_ZERO. I've did a quick check and we have a constant called FILTER_FLAG_ALLOW_FRACTION so maybe JSON_PRESERVE_FRACTION would be a bit simpler and consistent. But that would still imply that without this option we truncate (non-zero) fractional parts, so maybe something like JSON_PRESERVE_ZERO_FRACTION. I think PRESERVE is better than ADD because we aren't really adding something but making sure that it won't be lost through the json_encode.
-- Ferenc Kovács @Tyr43l - http://tyrael.hu

Juan Basso

11 years ago
I really like the new name and the consistence with the rest of php. If no one else has a complain about it I will update the RFC and open for voting, right? Juan Basso On Jan 5, 2015 7:31 AM, "Ferenc Kovacs" <tyra3l@gmail.com> wrote:

Juan Basso

11 years ago
I renamed the constant name on the RFC. Can I open the voting? On Wed, Jan 7, 2015 at 7:14 PM, Juan Basso <jrbasso@gmail.com> wrote:

Andrew Faulds

11 years ago
> On 11 Jan 2015, at 02:26, Juan Basso <jrbasso@gmail.com> wrote: > > I renamed the constant name on the RFC. Can I open the voting?
Hey Juan, It’s been long enough, and the constant name is a minor issue. Go for it. :)
-- Andrea Faulds http://ajf.me/