Re: json_encode() behavior for incorrectly encoded strings

From: Date: Thu, 21 Jun 2012 14:25:49 +0000
Subject: Re: json_encode() behavior for incorrectly encoded strings
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-60924@lists.php.net to get a copy of this message
On Thu, Jun 21, 2012 at 4:12 PM, Daniel Convissor <danielc@analysisandsolutions.com> wrote: > Hi Nikita: > >> PHP <= 5.3.13, PHP 5.4, master behave as follows when an invalid UTF-8 >> string is encountered: >>  * A warning is thrown, but only if display_errors=off > > So the warning is put into the error log?  But only if display_errors is > off?  And if display_errors is on, no warning is produced? > > That's very counter-intuitive and un-PHP-like.  Someone mentioned it's for > security reasons.  By that logic, we should get rid of all error > messages because they all reveal some information that can be used by > attackers. Yes, I agree with this, but other people thing differently about it ;) Personally I'd actually remove the warning completely with the return false behavior. The return value makes clear that there was an error and json_last_error() can be used to determine what exactly went wrong. The warning seems redundant in this case and could actually make the use more complicated. Nikita

« previous php.internals (#60924) next »