transit-php icon indicating copy to clipboard operation
transit-php copied to clipboard

Noisier warning if JSON_PRESERVE_ZERO_FRACTION not available

Open sminnee opened this issue 6 years ago • 2 comments

If JSON_PRESERVE_ZERO_FRACTION isn't defined, then this library converts any whole-number float value to an integer. This can cause some hard-to-find bugs and it would be better if this script complained more loudly.

I think this package should have a check for if(!defined('JSON_PRESERVE_ZERO_FRACTION')) and throw an E_USER_WARNING or exception. It could either do this all the time, or it could do it only if float / whole-number-float values are included in a data payload.

Generally speaking I would advise against using this package if JSON_PRESERVE_ZERO_FRACTION wasn't available. Probably, I would recommend that the user of the package upgrades.

What do you think?

sminnee avatar Jul 10 '18 05:07 sminnee

This is where the error manifests itself https://github.com/nette/utils/blob/master/src/Utils/Json.php#L34

sminnee avatar Jul 10 '18 05:07 sminnee

Nice catch! Would you like to send PR, please?

honzabrecka avatar Jul 10 '18 10:07 honzabrecka