Req #79189 [NEW]: json_encode with JSON_NUMERIC_CHECK and extra option
| From: | dalius dot ulevicius at gmail dot com | Date: | Wed, 29 Jan 2020 09:32:56 +0000 |
| Subject: | Req #79189 [NEW]: json_encode with JSON_NUMERIC_CHECK and extra option | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-225211@lists.php.net to get a copy of this message | ||
From: dalius dot ulevicius at gmail dot com
Operating system: Ubuntu
PHP version: 7.4.2
Package: JSON related
Bug Type: Feature/Change Request
Bug description:json_encode with JSON_NUMERIC_CHECK and extra option
Description:
------------
JSON_NUMERIC_CHECK does not respect the definition of numbers.
I think will be great to add extra option like (JSON_NUMERIC_LEADZERO),
to do not trailing zeros at the lead.
Extra reported as a bug many years ago:
https://bugs.php.net/bug.php?id=70680
Test script:
---------------
print_r(json_encode(array("shouldBeString0123456" => "0123456",
"shouldBeString+0123456" => "+0123456", "isInt" =>
"123456"),
JSON_NUMERIC_CHECK | JSON_NUMERIC_LEADZERO));
Expected result:
----------------
{
"shouldBeString0123456":"0123456",
"shouldBeString+0123456":"+0123456",
"isInt":123456
}
Actual result:
--------------
{
"shouldBeString0123456":123456, // Bad with JSON_NUMERIC_CHECK
"shouldBeString+0123456":123456, // Bad with JSON_NUMERIC_CHECK
"isInt":123456 // Good
}
--
Edit bug report at https://bugs.php.net/bug.php?id=79189&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79189&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79189&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79189&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79189&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79189&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79189&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79189&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79189&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79189&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79189&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79189&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79189&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79189&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79189&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79189&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79189&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79189&r=mysqlcfg