Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60954 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86748 invoked from network); 24 Jun 2012 01:03:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jun 2012 01:03:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@lerdorf.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@lerdorf.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lerdorf.com from 209.85.160.42 cause and error) X-PHP-List-Original-Sender: rasmus@lerdorf.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:33761] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/42-04949-A6766EF4 for ; Sat, 23 Jun 2012 21:03:40 -0400 Received: by pbbrp12 with SMTP id rp12so5613957pbb.29 for ; Sat, 23 Jun 2012 18:03:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=XBNTdYElyRGphSrZ+J/jIPEe2aN1LHmkgwgKIg52YQk=; b=UmuTtOGP55EqFMu0dvYEGa8MsS/DO4HX6e8lus2iTltyo8aR4aD9C1F2P2iH/0FPZE kmhoMxhW/uoBuhsrZ1wzOiX/DWG3oUSXenMfkLZYRp4sqJ0c4z+jPnL0404F5haYTXWJ Jn34sIVLxXgzd1gMxjz74gfV4A5oQLNswyEodwgaMmipuyY02FhUXc7VOJjJ3s6uYPKD zytdBlUH9PD8hzMsDi7yP7EkJPPIRoSRTtfk7Q6sDGS4Gc8TlVuzvStl5RG3k0Ws3wbs 0JoJTZlonLX6weMX4aeIANVpVOVnDlV+hUgG1DkwluqnyYXzYu5IqUzI2cbS7WT0esLh vIJA== Received: by 10.68.227.163 with SMTP id sb3mr25961221pbc.74.1340499816243; Sat, 23 Jun 2012 18:03:36 -0700 (PDT) Received: from [192.168.200.5] (c-50-131-44-225.hsd1.ca.comcast.net. [50.131.44.225]) by mx.google.com with ESMTPS id np8sm3758893pbc.71.2012.06.23.18.03.35 (version=SSLv3 cipher=OTHER); Sat, 23 Jun 2012 18:03:35 -0700 (PDT) Message-ID: <4FE66766.2070004@lerdorf.com> Date: Sat, 23 Jun 2012 18:03:34 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120430 Thunderbird/12.0.1 MIME-Version: 1.0 To: Stas Malyshev CC: =?UTF-8?B?Sm9oYW5uZXMgU2NobMO8dGVy?= , Nikita Popov , Daniel Convissor , PHP internals References: <20120621141241.GA25789@analysisandsolutions.com> <4FE33EDF.2000409@lerdorf.com> <4FE61E9D.5050908@sugarcrm.com> <1340492604.11164.14.camel@guybrush> <4FE64BDF.6050208@sugarcrm.com> In-Reply-To: <4FE64BDF.6050208@sugarcrm.com> X-Enigmail-Version: 1.5pre Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQlWeyCcwMVcRqQ119D5OVsTY9iN7QfTWclAr9jdIn/Zz03k+DgGIOEN2Cc3chJRfTj+vqJz Subject: Re: [PHP-DEV] json_encode() behavior for incorrectly encoded strings From: rasmus@lerdorf.com (Rasmus Lerdorf) On 06/23/2012 04:06 PM, Stas Malyshev wrote: > Hi! > >> Maybe it is simply time to rethink the error handling. > > This is true, current error handling has many deficiencies and is also > very expensive even when the errors are muted (we still produce the > whole error string, etc. even if we never display it). Unfortunately, BC > concerns prevailed last times we tried to fix it, but maybe somebody has > new ideas on that. Yes, I think we need to rethink warnings for the cases where the error is part of the common use case. htmlspecialchars() getting passed invalid Unicode chars, json_decode() getting non-json and json_encode() getting non UTF-8 chars. These are all cases where if the function generates an error, in order to avoid that error you have to do some work beforehand to sanitize the input data which is a useless thing to have to do since the functions themselves can do it. For json_decode() we have json_last_error() to help with debugging. Maybe a solution is to generalize that. We already mostly have it via $php_errormsg/error_get_last(). And yes, I don't think a warning from json_encode() is useful because to properly avoid it you would need an iconv() call before calling it and that is pure overhead. Short of that your only recourse is to use @ and that just isn't the right answer. In this I would suggest just having it return false and have json_last_error() apply to json_encode() as well. -Rasmus