Bug #81344 [NEW]: JSON_NUMERIC_CHECK Behaviour

From: Date: Tue, 10 Aug 2021 12:32:03 +0000
Subject: Bug #81344 [NEW]: JSON_NUMERIC_CHECK Behaviour
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235726@lists.php.net to get a copy of this message
From: tobiasoitzinger at gmail dot com Operating system: Ubuntu 20.04 PHP version: 8.0.9 Package: JSON related Bug Type: Bug Bug description:JSON_NUMERIC_CHECK Behaviour Description: ------------ When using JSON_NUMERIC_CHECK with json_encode, the behaviour differs starting from php8. I couldn't find if this is documented somewhere, i am also not sure if this is a bug. json_encode currently has no option to specify if leading zeros schould be kept. See: https://bugs.php.net/bug.php?id=79189 This might be correct, since according to the JSON specification, a number cannot start with 0, there is also a bug for this: https://bugs.php.net/bug.php?id=70680 If some wanted to keep the leading zero, a workaround could be used to add a space character after the number that should keep it's leading zeros. In php < 8 using JSON_NUMERIC_CHECK: 1. with a whitespace after the number e.g "01234 " it would convert to (string)01234 2. without a whitespace after the number e.g "01234" it would convert to (int)1234 In php >= 8 using JSON_NUMERIC_CHECK: Whitespaces do not matter, it always converts it to (int)1234. The behaviour changed, which might be correct. However as stated above i couldn't find this in the changelog or somewhere else documented, maybe it is a bug / unexpected behaviour? Test script: --------------- print_r(json_encode('01234 ', JSON_NUMERIC_CHECK)); Expected result: ---------------- "01234 " Actual result: -------------- 1234 -- Edit bug report at https://bugs.php.net/bug.php?id=81344&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81344&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81344&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81344&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81344&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81344&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81344&r=support Expected behavior: https://bugs.php.net/fix.php?id=81344&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81344&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81344&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81344&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81344&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81344&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81344&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81344&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81344&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81344&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81344&r=mysqlcfg

« previous php.bugs (#235726) next »