Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60951 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 79251 invoked from network); 23 Jun 2012 22:50:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jun 2012 22:50:20 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:38352] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 33/31-04949-92846EF4 for ; Sat, 23 Jun 2012 18:50:19 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 1ED017000430 for ; Sat, 23 Jun 2012 23:50:15 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id hJseJE7dQDQa for ; Sat, 23 Jun 2012 23:50:14 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id D2F8C7000426 for ; Sat, 23 Jun 2012 23:50:14 +0100 (WEST) Received: from damnation.nl.lo.geleia.net (damnation.nl.lo.geleia.net [IPv6:2001:470:94a2:4:4866:11bc:1688:8089]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 665F6200707A for ; Sat, 23 Jun 2012 23:50:13 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: internals@lists.php.net References: <20120621141241.GA25789@analysisandsolutions.com> <4FE33EDF.2000409@lerdorf.com> <4FE61E9D.5050908@sugarcrm.com> Date: Sun, 24 Jun 2012 00:50:13 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: <4FE61E9D.5050908@sugarcrm.com> User-Agent: Opera Mail/12.00 (Win32) Subject: Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Sat, 23 Jun 2012 21:53:01 +0200, Stas Malyshev wrote: > Hi! > >> The warning for invalid UTF-8 stays intact and is thrown also with >> display_errors = On. If this behavior is undesired this can be remedied >> later. > > Must we discuss it 1000 times anew? There was a reason why it didn't > throw warning when display_errors is on. The reason is that it is very > easy to feed the server configured with display_errors = on wrong JSON > and thus force it to reveal information, and this is largely beyond the > control of application writer. I find this argument unconvincing. If json_encode() is not supposed to receive badly encoded data, then it's the application writer's responsibility to make sure that the data is correctly encoded. If, on the other hand, you think that's actually not a error on the part of the caller to call json_encode() with badly encoded data (i.e., just like htmlspecialchars() -- from which I removed the warning removed in 5.4 --, json_encode() also accumulates the responsibility validating some aspects of the input), then there's no reason to have a warning at all. In other words, if it's a precondition of json_encode() that the input is correctly encoded (and the check is just a form of safe programming), then there's indeed an error on the part of the application writer, if it isn't, then there's no reason for any sort of warning. (By the way, I'd prefer no warning at all, both for this and for inf/NAN. We already can get the error from json_last_error() if we want to) -- Gustavo Lopes