note 127427 added to json.constants
| From: | nikospapoutsis at main dot php dot net | Date: | Sat, 06 Aug 2022 10:47:11 +0000 |
| Subject: | note 127427 added to json.constants | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219377@lists.php.net to get a copy of this message | ||
Be EXTREMELY cautious when using the code majid4466 at gmail dot com provided, or JSON_NUMERIC_CHECK
in general.
For example, in php 7.4 and 8.1 with precision: 14 and serialize_precision: -1 we get:
<?php
$array = ['â¬', 55.6666666666666666, 'http://example.com/some/cool/page',
'000337', '55.6666666666666666'];
echo $case1 = json_encode($array);
echo $case2 = json_encode($array, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES );
echo $case3 = json_encode($array, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES |
JSON_NUMERIC_CHECK);
["\u20ac",55.666666666666664,"http:\/\/example.com\/some\/cool\/page","000337","55.6666666666666666"]
// in $case1, both euro sign and the url change but we also lost a digit in our unquoted float (due
to precision)
["â¬",55.666666666666664,"http://example.com/some/cool/page","000337","55.6666666666666666"]
// in $case2, both euro sign and the url stay exactly the same but we still lost a digit in our
unquoted float (due to precision)
["â¬",55.666666666666664,"http://example.com/some/cool/page",337,55.666666666666664]
// in $case3, we once again keep euro sign and the url intact but this time not only our unquoted
float lost a digit
// but the same happened to our quoted float and the number/string lost its leading zeros too
Also, note that in php 5.x you will probably get some different but equally wrong results as default
values may be different and some functions have changed internally as well.
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.163 (proxied: 62.74.59.220)
----
Manual Page -- https://php.net/manual/en/json.constants.php
Edit -- https://main.php.net/note/edit/127427
Del: integrated -- https://main.php.net/note/delete/127427/integrated
Del: useless -- https://main.php.net/note/delete/127427/useless
Del: bad code -- https://main.php.net/note/delete/127427/bad+code
Del: spam -- https://main.php.net/note/delete/127427/spam
Del: non-english -- https://main.php.net/note/delete/127427/non-english
Del: in docs -- https://main.php.net/note/delete/127427/in+docs
Del: other reasons-- https://main.php.net/note/delete/127427
Reject -- https://main.php.net/note/reject/127427
Search -- https://main.php.net/manage/user-notes.php