chromephp
chromephp copied to clipboard
PHP Warning: json_encode(): in ChromePhp.php on line 405
PHP Warning: json_encode(): double NAN does not conform to the JSON spec, encoded as 0 in ChromePhp.php on line 405
Maybe, we can fix this warning.
This maybe helps a bit: http://stackoverflow.com/questions/13581843/php-how-to-encode-infinity-or-nan-numbers-to-json
Thanks!
I think the warning is valid. Why do you think it's important to prevent it?
You are right, this warning is valid. Because this occurs when I have NaN in a variable.
But wouldn't it be better to really have a NaN? According to the warning the NaN will be encoded as 0. So as I understand, I really don't know if the logged variable is a 0 or a NaN (encoded as 0).
And by the way, I look in my error logs to ensure my application is working without any errors. So this warning in the logs can use a lot of lines in my error log.
It is not possible to represent NaN with JSON. As JSON is used, these error-conditions need either to be filtered out or not dealt with that. It would be perhaps most useful to encode these non-encode able values differently, like a string with value "NaN" or something similar.
Projects that do the same (like FirePHP) might show how an implementation could be done. I just don't have a similar report at hand within that project. But I assume it exists.
I suggest merging #55, in which @ErikKrause not only fixed this, but did an excellent job in making the library more friendly to users coming from FirePHP without modifying the current default behaviour.
Additionally, I suggest rendering NaNs with nulls (imho the nicer option), as I shown here together with an important fix on @ErikKrause work.