Bug #77997 [NEW]: Json_last_error hugely suprising

From: Date: Thu, 09 May 2019 15:53:27 +0000
Subject: Bug #77997 [NEW]: Json_last_error hugely suprising
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220800@lists.php.net to get a copy of this message
From: danack Operating system: PHP version: 7.3.5 Package: *General Issues Bug Type: Bug Bug description:Json_last_error hugely suprising Description: ------------ When using JSON_THROW_ON_ERROR, json_last_error no longer refers to the previous function call, but instead the last json_(encode|decode) that doesn't have the JSON_THROW_ON_ERROR flag set. Test script: --------------- $foo = json_decode('[bar'); // many lines of code. $bar = json_encode('Hello world!', JSON_THROW_ON_ERROR); if (json_last_error() !== JSON_ERROR_NONE) { // Note, this is not true. The encoding was fine, but // json_last_error gets the error from the json_decode before throw new Exception("encoding went wrong!"); } echo "All is fine"; Expected result: ---------------- json_last_error() gives the error for the last call, regardless of the flag. Actual result: -------------- json_last_error() give the error for the previous that did not have JSON_THROW_ON_ERROR set. -- Edit bug report at https://bugs.php.net/bug.php?id=77997&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77997&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77997&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77997&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=77997&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=77997&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=77997&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=77997&r=needscript Try newer version: https://bugs.php.net/fix.php?id=77997&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=77997&r=support Expected behavior: https://bugs.php.net/fix.php?id=77997&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=77997&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=77997&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=77997&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77997&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=77997&r=dst IIS Stability: https://bugs.php.net/fix.php?id=77997&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=77997&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=77997&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=77997&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=77997&r=mysqlcfg

« previous php.bugs (#220800) next »