Bug #79908 [NEW]: json_decode decodes negative zero as positive zero

From: Date: Tue, 28 Jul 2020 13:02:21 +0000
Subject: Bug #79908 [NEW]: json_decode decodes negative zero as positive zero
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-228251@lists.php.net to get a copy of this message
From: stefan at HDmeteo dot com Operating system: PHP version: 7.4.8 Package: JSON related Bug Type: Bug Bug description:json_decode decodes negative zero as positive zero Description: ------------ While php_encode stores a negative zero float as "-0" and preserves its sign, the subsequent php_decode loses the sign and decodes "-0" as "0". Test script: --------------- $array = [round(-0.1), round(0.1)]; // [-0,0] print_r($array); // Array ( [0] => -0 [1] => 0 ) $json = json_encode($array, true); // "[-0,0]" $array = json_decode($json); // [0,0] print_r($array); // Array ( [0] => 0 [1] => 0 ) Expected result: ---------------- Array ( [0] => -0 [1] => 0 ) Actual result: -------------- Array ( [0] => 0 [1] => 0 ) -- Edit bug report at https://bugs.php.net/bug.php?id=79908&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79908&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79908&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79908&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79908&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79908&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79908&r=support Expected behavior: https://bugs.php.net/fix.php?id=79908&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79908&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79908&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79908&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79908&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79908&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79908&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79908&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79908&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79908&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79908&r=mysqlcfg

« previous php.bugs (#228251) next »