Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big integers should be returned as string (~JSON_BIGINT_AS_STRING) #9

Closed
JanTvrdik opened this issue Apr 9, 2014 · 8 comments
Closed

Comments

@JanTvrdik
Copy link
Contributor

I think that it is better to return large integers as string instead of casting them to float.

What do you think? Any tips, how to efficiently decide whether string contains integer larger than MAX_INT?

@Majkl578
Copy link

Majkl578 commented Apr 9, 2014

Any tips, how to efficiently decide whether string contains integer larger than MAX_INT?

Some cute regexp?

@JanTvrdik
Copy link
Contributor Author

This is what I have now – JanTvrdik@c302826

@JanTvrdik
Copy link
Contributor Author

What to do with numbers such as 0x123456789123456781345678913? I would prefer to return them as decimal string however I'm not aware of any efficient solution to perform the conversion.

@milo
Copy link
Member

milo commented Apr 9, 2014

What about E_USER_WARNING on big number? To force user enclose it in quotes as a string. JSON has the JSON_BIGINT_AS_STRING only for interoperability between 32-bit and 64-bit systems.

@milo
Copy link
Member

milo commented Apr 9, 2014

What to do with numbers such as 0x123456789123456781345678913? I would prefer to return them as decimal string however I'm not aware of any efficient solution to perform the conversion.

The only sane way I know in PHP is the GMP extension.

@Majkl578
Copy link

Majkl578 commented Apr 9, 2014

What about E_USER_WARNING on big number? To force user enclose it in quotes as a string.

Please, don't. JSON NEON is not something you always manually construct in the application, it's rather given from elsewhere, really not something you control directly (thus should not trigger an error).

@JanTvrdik
Copy link
Contributor Author

Please, don't. JSON is not something you manually construct

  1. We're talking about NEON here 2) JSON RFC allows a JSON parser to restrict the range of numbers it can handle

But still agreed, warning is the solution I would like to avoid.

@mishak87
Copy link

There is no sane way how to handle big numbers or have you forgotten about very large decimals?

It should be string representation of given number or native PHP representation if possible. This is the simple solution

We can add custom number parser into mix as a fallback or parameter with default set to sane parser. Quite easy, hard problem of what to do with numbers will be solved by user.

In my magic ball I see this heading to custom number parser with default implementation that handles numbers of all colours and sizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants