Re: json_encode() behavior for incorrectly encoded strings

From: Date: Thu, 21 Jun 2012 06:51:15 +0000
Subject: Re: json_encode() behavior for incorrectly encoded strings
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-60914@lists.php.net to get a copy of this message
On Thu, Jun 21, 2012 at 2:47 PM, Pierre Joye <pierre.php@gmail.com> wrote: > hi, > > On Thu, Jun 21, 2012 at 12:21 AM, Nikita Popov > <nikita.ppv@googlemail.com> wrote: > >> 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. > > Well, not sure we have to discuss why such thing is bad. > display_errors must be respected. Agree, and it shall be, no any exception. thanks > > Also I suspect that this change should not even be merged in 5.4 nor > 5.3. At least not without real testing. > >> 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. > > 5.3 should be brought in line with 5.4. > > Cheers, > -- > Pierre > > @pierrejoye | http://blog.thepimp.net | > http://www.libgd.org > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Laruence  Xinchen Hui http://www.laruence.com/

« previous php.internals (#60914) next »