Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79930 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77591 invoked from network); 25 Dec 2014 04:06:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Dec 2014 04:06:52 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.200 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.200 imap1-2.ox.privateemail.com Received: from [192.64.116.200] ([192.64.116.200:41011] helo=imap1-2.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/E0-07310-B5D8B945 for ; Wed, 24 Dec 2014 23:06:51 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 77537B00087; Wed, 24 Dec 2014 23:06:48 -0500 (EST) X-Virus-Scanned: Debian amavisd-new at imap1.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap1.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Vooa2sRBW1bF; Wed, 24 Dec 2014 23:06:48 -0500 (EST) Received: from [192.168.0.13] (unknown [94.13.96.117]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id D600EB00085; Wed, 24 Dec 2014 23:06:46 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: Date: Thu, 25 Dec 2014 04:06:14 +0000 Cc: =?utf-8?Q?Johannes_Schl=C3=BCter?= , Pierre Joye , PHP internals , Laruence Content-Transfer-Encoding: quoted-printable Message-ID: <51160B8D-F662-458E-A0E0-1F37DC3A8869@ajf.me> References: <946C1B1D-30B8-4029-A5A1-73D515A017D8@ajf.me> <1419428487.29904.6.camel@kuechenschabe> <5E26F21C-EA41-43FF-8DDB-D0A985AB4197@ajf.me> <1419463624.28792.6.camel@kuechenschabe> To: Levi Morrison X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] About SUCCESS/FAILURE From: ajf@ajf.me (Andrea Faulds) > On 24 Dec 2014, at 23:53, Levi Morrison wrote: >=20 > On Wed, Dec 24, 2014 at 4:27 PM, Johannes Schl=C3=BCter > wrote: >> On Wed, 2014-12-24 at 11:13 -0700, Levi Morrison wrote: >>=20 >>> I'm asking for specific things. The reason is that some API's do a >>> non-zero error code; the fact that they are negative is a detail = that >>> we should not need to care about. >>=20 >> My guess is that positive values more often might have a meaning ("5 >> items changed", "address 0x1234") whereas negative values less often >> have a meaning. Also passing -1 as parameter is more often invalid. = Thus >> passing -1 is making debug output look more suspicious. >>=20 >> (while there are cases where -1 is valid, see recent famous = pid >> =3D fork(); /* ... */ kill(pid, SIGKILL); issue) >=20 > I don't think this is the same use case as SUCCESS and FAILURE. Many > functions have an out parameter which is only valid when the returned > value is SUCCESS. This is not the same thing as an API which returns > an integer and just happen to embed error state in the negative range. > Notably, it doesn't make sense to do `strpos() =3D=3D SUCCESS` to = check > success; these are different cases. My question is specifically > directed at the ones that use SUCCESS and FAILURE: which ones require > FAILURE to be negative instead of the normal UNIX-ism of non-zero? >=20 > For the record I am in favor of an enum such as `zend_status` or some > other name which indicates whether an operation succeeded or not for > the reasons already cited in this thread. I just don't see why FAILURE > needs to be negative and want to know why this is the case. Hi Levi, Again, I think the reason FAILURE is -1 is for consistency with other = functions which use negative return values on error. Some functions = return negative error codes, others just -1. Some functions return = useful positive values, others just 0. But the idea is that all = functions return a negative number on error, so you can use if (foo() < = 0) to check for errors. That=E2=80=99s the point of making FAILURE be = -1, AIUI. It makes it consistent with other things, like fork() or = strpos(). Thanks. -- Andrea Faulds http://ajf.me/