Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35071 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42328 invoked by uid 1010); 1 Feb 2008 20:25:17 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 42313 invoked from network); 1 Feb 2008 20:25:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2008 20:25:17 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.198.188 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.198.188 rv-out-0910.google.com Received: from [209.85.198.188] ([209.85.198.188:43872] helo=rv-out-0910.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/DD-31091-C2083A74 for ; Fri, 01 Feb 2008 15:25:17 -0500 Received: by rv-out-0910.google.com with SMTP id k15so823972rvb.23 for ; Fri, 01 Feb 2008 12:25:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=E0eHOBOo4gVC1KBTjGBZnuV4/Pjtg03vOw3tMJaXTEk=; b=HIq4AEDAFV5oFG2cKK5f8SM1bEAjWNK/8S0lTZrY/bQFkMsYbVIhdNdej4wNSWRYVAcbIMLLs5qr0S5x255y/KWAJt+SsW+kxIMg3Dn/PV72hNVFpBxmonDkNdO9sCRhQCp1jM6p3Xn08LTQKvIyi05la/HBnjkCP55BAlVXrZE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=c032Z0fIZy9OjBFg/YJUQXnNpvk3kd6y3dE4gcg5uctpUKNfzwFd0Ki1b1qJw9K/kSNqRtb/0Mj3yl8K53ykM4WQMqnaKGy5MheH7P0QpMfzbu9gOlo9N+KwAmCnpQCjfbTdlV6aPkdxKmUc9Gv9BrNy/KGiN5hleyPB1knCcTE= Received: by 10.141.211.13 with SMTP id n13mr2811500rvq.12.1201897509919; Fri, 01 Feb 2008 12:25:09 -0800 (PST) Received: by 10.141.151.21 with HTTP; Fri, 1 Feb 2008 12:25:09 -0800 (PST) Message-ID: Date: Fri, 1 Feb 2008 21:25:09 +0100 To: "Stanislav Malyshev" Cc: "Cristian Rodriguez" , php-dev In-Reply-To: <47A37BD9.2030804@zend.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <479A60BA.7030905@zend.com> <7d5a202f0802011113x3d141a9fqc577f051b35e6d6b@mail.gmail.com> <47A37BD9.2030804@zend.com> Subject: Re: [PHP-DEV] json_encode() bug From: pierre.php@gmail.com ("Pierre Joye") On Feb 1, 2008 9:06 PM, Stanislav Malyshev wrote: > > Stupid question, who actually checks for E_* in his code at runtime > > after having called such functions? Not me and I would hate to. It > > sounds to me like a perfect exception use case. As this function can > > General policy in PHP as far as I know is that non-OO functions do not > do exceptions. > > > return nearly everything scalar we have (boolean, string, null, > > integer,...) we can't use our normal "returns FALSE on failure". > > This function can return only a string, but I'm not sure returning false > if somewhere in some value deep down your data is some bad utf-8 is > warranted. It is doable, though, but I'm afraid most of current code > never check for return of json_encode() so they are in for big surprises > when json_encode won't produce valid JSON. Oh right, I thought about/read json_decode. But the idea is the same yes. Not checking return values is a very bad habit, I can't count how many times I saw codes dying miserably only because they don't check returns values. Would it make sense to use exception for such cases? Aka to change our policy? I'm not an excpeption fan, but these cases are good examples of exception usages. We can invent a meta type "error" but it would be rather confusing ;) -- Pierre http://blog.thepimp.net | http://www.libgd.org