json_encode() behavior for incorrectly encoded strings

From: Date: Wed, 20 Jun 2012 22:21:50 +0000
Subject: json_encode() behavior for incorrectly encoded strings
Groups: php.internals 
Request: Send a blank email to internals+get-60908@lists.php.net to get a copy of this message
Hi internals! We currently have a big mess concerning the behavior of json_encode() with incorrectly encoded UTF-8 strings. To summarize the situation: PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 string is encountered: * The invalid string is replaced with "null", thus creating a partial JSON serialization * json_encode() returns the partial serialization, *not* false as it should * A warning is thrown, but only if display_errors=off * json_last_error() returns JSON_ERROR_UTF8 PHP 5.3.14 behaves as follows: * json_encode() returns false, as it should * A warning is thrown always, even with display_errors=on * json_last_error() returns JSON_ERROR_UTF8 * If the PHP_JSON_PARTIAL_OUTPUT_ON_ERROR option is specified, the old behavior is restored The reason for this situation is that a patch was applied for all branches, and then reverted, because Stas didn't consider the change towards always throwing a warning (even with display_errors=on) appropriate without further discussion. The backout though was done only on PHP 5.4 and master, but *not* on the PHP 5.3 branch. Thus we now have differing behavior between 5.3 and 5.4 (and PHP <= 5.3.13). So, I'd like to ask whether the patch can be reapplied to 5.4 and master or whether we should do something else to solve this problem. Nikita

« previous php.internals (#60908) next »