Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79916 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46977 invoked from network); 24 Dec 2014 09:39:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Dec 2014 09:39:23 -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 Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.174 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.174 mail-qc0-f174.google.com Received: from [209.85.216.174] ([209.85.216.174:49948] helo=mail-qc0-f174.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C2/70-44085-9C98A945 for ; Wed, 24 Dec 2014 04:39:21 -0500 Received: by mail-qc0-f174.google.com with SMTP id c9so5626127qcz.5 for ; Wed, 24 Dec 2014 01:39:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=YVElKqWSjIHpgETATF9l0LvtRrVjmfipMuocoFriRUA=; b=y5uQbTzeMuAjOjUNce5QtQxCvoh/xDcgpC50LoVJTEHGe/sOH6XPLdNklXSyVprXUx W0pvKVxLlzD9iQotPEswxq4HDGbiv+6E+zRmXo4AzyEefwKYSFFFrJNS7zbQuqweNUOt wOrAhg4mLdZzatxqjI4/bYIeaREZtLx1tU58vDRZeUdmDz3kUO11R6KY3cbrPQMGCM3V r2cLA8Wk/EMAKhV0vtPwt0zmTRotaHZJKXBbnBhvDnsTsrK/WZCyUQ0wBRPky9BVKtha pIojmhQZl/WSjLt/b4N6yw2Uwoa4VW0NZmUiS8giTyvRJ+BJ99ybldLmhe4FmSmYJAaC 4cDQ== MIME-Version: 1.0 X-Received: by 10.140.80.136 with SMTP id c8mr29720504qgd.30.1419413959064; Wed, 24 Dec 2014 01:39:19 -0800 (PST) Received: by 10.140.22.106 with HTTP; Wed, 24 Dec 2014 01:39:18 -0800 (PST) In-Reply-To: References: <946C1B1D-30B8-4029-A5A1-73D515A017D8@ajf.me> <549A6D5A.6060307@gmail.com> Date: Wed, 24 Dec 2014 20:39:18 +1100 Message-ID: To: Xinchen Hui Cc: Stas Malyshev , PHP internals , Andrea Faulds Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] About SUCCESS/FAILURE From: pierre.php@gmail.com (Pierre Joye) On Wed, Dec 24, 2014 at 7:53 PM, Xinchen Hui wrote: > On Wed, Dec 24, 2014 at 3:57 PM, Pierre Joye wrote: >> >> On Dec 24, 2014 2:38 PM, "Stanislav Malyshev" wrote: >>> >>> Hi! >>> >>> > But: return 0 and return FAILURE... which is simpler? >>> >>> It's equally simple to write, but FAILURE of course is way simpler to >>> understand when read. >> >> I totally agree. >> >> I do not care much about the value of failure or success but I am tired to >> have to read the code to see if it is 0, 1, or -1 on failure. >> >> The kind of uniformization I would like to see for the php internals APIs. >> >> About the argument for the lack of info in function signature: >> >> A simple typedef will solve it, for the good: >> >> status php_foo(); >> >> Or something along this line. >> >> Yes, it will mean yet another large set of changes for ext developers. But >> at this point, it may be a good time to do it. > hmm, okey > > so, make the functions which use SUCCESS/FAILURE return php_success type? > > and maybe also typedef php_success php_status? more like: #include /* From http://lxr.php.net/xref/PHP_TRUNK/Zend/zend_types.h#48 */ typedef enum { SUCCESS = 0, FAILURE = -1, /* this MUST stay a negative number, or it may affect functions! */ } ZEND_RESULT_CODE; typedef enum ZEND_RESULT_CODE status; status func (status s) { printf("%s\n", s == FAILURE ? "FAILURE" : "SUCCESS"); return s; } int main (void) { status s; s = SUCCESS; func (s); s = FAILURE; func(s); return 0; } according to the current way FAILURE/SUCCESS are defined. Cheers, -- Pierre @pierrejoye | http://www.libgd.org