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

PHP Warning: json_encode(): in ChromePhp.php on line 405 #35

Open
marcusfritze opened this issue Sep 9, 2013 · 4 comments
Open

PHP Warning: json_encode(): in ChromePhp.php on line 405 #35

marcusfritze opened this issue Sep 9, 2013 · 4 comments

Comments

@marcusfritze
Copy link

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!

@hakre
Copy link

hakre commented Sep 14, 2014

I think the warning is valid. Why do you think it's important to prevent it?

@marcusfritze
Copy link
Author

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.

@hakre
Copy link

hakre commented Sep 16, 2014

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.

@lorenzos
Copy link

lorenzos commented Mar 13, 2017

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.

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

3 participants