note 113416 deleted from function.json-encode by cmb
| From: | cmb@php.net | Date: | Sun, 04 Nov 2018 10:05:28 +0000 |
| Subject: | note 113416 deleted from function.json-encode by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-209608@lists.php.net to get a copy of this message | ||
Note Submitter: zac at javazac dot com
----
There is a gotcha that keeps getting me with JSON_NUMERIC_CHECK. At first it seems like the greatest
thing in the world if you are encoding data pulled from a db because it turns numeric strings into
seemingly appropriate ints or floats. Use with caution. I've been surprised a number of times
by "numbers" that really are strings ie really precise lat/long coords. json_encode with
the JSON_NUMERIC_CHECK will encode these as floats but the precision of the data is so large that
php actually rounds the number off. In this case I had to rework my code so that it didn't use
JSON_NUMERIC_CHECK and I manually cast fields as ints or floats as appropriate and skipped my
lat/long fields so that they stayed numeric strings.