Re: json_encode() bug

From: Date: Mon, 04 Feb 2008 09:28:34 +0000
Subject: Re: json_encode() bug
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-35162@lists.php.net to get a copy of this message
On Sun, 3 Feb 2008, Stanislav Malyshev wrote: > > Like I mentioned before (I think), it should not return an empty string of > > course because programmatically it's not possible to check for this. As most > > of our functions return false in those cases, so should this function. > > AFAIR false is not valid JSON, so it would break a lot of code. Also, I am not > sure we should change json_encode to return false on whole structure if one of > the fields contains invalid utf-8. Of course we should make it possible to detect if there is broken data. I think our normal mantra is "be strict with creating, be lenient while parsing". Because we're generating data here, we should *abort* if we find an error, and not return half baked results. To detect if we have broken data, the option is to check a return value. As normally this function returns a string, false (or null) is a good candidate for an error-result. regards, Derick -- Derick Rethans http://derickrethans.nl | http://ezcomponents.org | http://xdebug.org

« previous php.internals (#35162) next »