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

Elevation string float becomes null in getJSON() call #43

Closed
sandcore-dev opened this issue Jan 17, 2020 · 3 comments
Closed

Elevation string float becomes null in getJSON() call #43

sandcore-dev opened this issue Jan 17, 2020 · 3 comments
Labels

Comments

@sandcore-dev
Copy link
Contributor

Hi,

I was testing phpGPX with points from a database that contained timestamp, latitude, longitude and elevation and noticed that the JSON output had "null" in the elevation property. This is because the elevation was a string.

Remarkably enough, this problem did not occur when exporting to XML.

  1. Package version: 1.0-RC5, also tested on dev-master
  2. PHP version: 7.4.1

Expected behaviour

Silently cast the value to a float or null.

Possible solution

SerializationHelper::floatOrNull() should use is_numeric() instead of is_float() || is_integer()

Alternate solution

You could also throw an exception if the value is neither a float nor null. Maybe a 'strict mode' could be offered for people who prefer to get an exception.

@Sibyx
Copy link
Owner

Sibyx commented Jan 19, 2020

Hello, thank you for reporting issue. Would you like to offer a PR? Or I can check it out in next few days.

@Sibyx Sibyx added the bug label Jan 19, 2020
@sandcore-dev
Copy link
Contributor Author

Pull request #44 submitted. Not just about floatOrNull though.

@Sibyx
Copy link
Owner

Sibyx commented Jan 20, 2020

Looks good, thank you very much!

@Sibyx Sibyx closed this as completed Jan 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants