Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119579 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 49565 invoked from network); 20 Feb 2023 13:06:26 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Feb 2023 13:06:26 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 7E792180505 for ; Mon, 20 Feb 2023 05:06:25 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 20 Feb 2023 05:06:24 -0800 (PST) Received: by mail-pj1-f51.google.com with SMTP id na9-20020a17090b4c0900b0023058bbd7b2so1287122pjb.0 for ; Mon, 20 Feb 2023 05:06:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=SV93kzdBkkozKcrbr2oE/Fl35dPSwzVQsbKk157Vbp4=; b=Q83XnaaBsqGPAFIRo7wQlexJumAxVWzO+k0oPLOQDmtBD+tEAMltgefRrqfFE3ELvR 2dwT4UvQbNQRQyuQyKJmVkBsLGerIskfw3izhrNewisZBhxYSzmHvYR5DMx+F9cmIoxi nUiggKdsRMLVLfN2EFwOAaLTolLG9iQ0aCw9yvPAgMM6HWbEzXEWtywk2EtC06bj5ua6 9uRzjcAdxM2N8LLVnE3/lQuODJiCQxpBCTBhF2/kHPyYbGdM8IIa8IjBZxwTLQrgI1oW b/9Gbp3GzJZu5j2lv0+UrMYWbNYgmSQMD9n6+GPnGGwa2M6K97TX2EMlBsKeksxo1vDh eikw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SV93kzdBkkozKcrbr2oE/Fl35dPSwzVQsbKk157Vbp4=; b=kcLEoGIK7ahyvt9ED9RQESYY/fhFekacuUpbKCAVRWeLRZPlV3FPcGzFA4nVn+OV71 wKsAhzPychSBaFuU87ThbHWKjDJUfERPJ3D2t3SiY7DxgbqWpVZ8L0dalY0ek6KQg+7p xhZBS06djLUrsPN3lLDrZSQoUf6eCrYX8wka4J4GBL2D1FMhXrClL/3KrsghdqtaBDyy nFh+e9oj1hQH6TGPGmPMAwKBFpap1FlDo61A9365u/qt3EiMTUns++2WP0JVo8/ZGtzA AyB1447zUA1sc89WW08SDRA/q3JK1YqKHh0iBrt96Tjpx8QiSc2bgAeIm15+SwKXFp5E swDA== X-Gm-Message-State: AO0yUKXIoYaQc2YGBMED5I8n5B6DN2OhklPyDOSwDvH6FB9aUW27YhmC FXpvrBXjDBOCSUnjUBYe0PDepl1E+5oOmJUfVs8= X-Google-Smtp-Source: AK7set9uWPRPb+BVms56/lpdeHB0bJ8KmEzffk7EdzkqVX36i4fYhZTSdZSqjggXB80Lg6wPD/3qSdV4ZqJGe6KZFyk= X-Received: by 2002:a17:902:6901:b0:196:cca:a0b4 with SMTP id j1-20020a170902690100b001960ccaa0b4mr136067plk.20.1676898383720; Mon, 20 Feb 2023 05:06:23 -0800 (PST) MIME-Version: 1.0 References: <478d639f-9f09-4747-a21a-eb4bceb5c053@app.fastmail.com> In-Reply-To: <478d639f-9f09-4747-a21a-eb4bceb5c053@app.fastmail.com> Date: Mon, 20 Feb 2023 13:06:12 +0000 Message-ID: To: Nikita Popov Cc: Max Kellermann , Levi Morrison Content-Type: multipart/alternative; boundary="0000000000007c772105f52154f5" Subject: Re: [PHP-DEV] What's the purpose of zend_result? From: george.banyard@gmail.com ("G. P. B.") --0000000000007c772105f52154f5 Content-Type: text/plain; charset="UTF-8" On Sun, 19 Feb 2023 at 08:45, Nikita Popov wrote: > On Sun, Feb 19, 2023, at 09:21, Max Kellermann wrote: > > On 2023/02/19 08:56, Nikita Popov wrote: > > > If you have a function like zend_stream_open_function(), SUCCESS and > FAILURE are directly meaningful values. > > > > Agree, but that doesn't explain why FAILURE needs to be negative. > > I expect that there are two main reasons for that: > - There are probably some places that return a (non-negative) value or > FAILURE. > - There are probably some places that check for success/failure using >= > 0 and < 0. Another POSIX-ism. > > I don't think we endorse such usage, but it likely exists. > > Let me turn the question around: Is there some reason to change the value > of FAILURE at this point? > > > > The current guideline for use of bool and zend_result in php-src is > that bool is an appropriate return value for "is" or "has" style functions, > which return a yes/no answer. zend_result is an appropriate return value > for functions that perform some operation that may succeed or fail. > > > > What does the return value of these functions mean? > > > > - zend_make_printable_zval() > > - zend_make_callable() > > - zend_parse_arg_bool() > > - zend_fiber_init_context() > > - zend_observer_remove_begin_handler() > > - php_execute_script()1 > > > > If I understand the guideline correctly, then those examples (and > > countless others) are defective and should be fixed, correct? > > At least in principle, yes. Of course, actually doing a change may not > always be worthwhile, especially as this might result in a silent behavior > change for extensions (as putting the return value into an "if" would > invert behavior now). > > I believe Girgias has done extensive work on making the int vs bool vs > zend_result situation more consistent, so you might want to coordinate with > him. > > Regards, > Nikita Yeah, I spent a lot of time around the release of PHP 8.0 and a bit in between releases to convert various int types to bool or zend_result just to make the API clearer. One of the main cases I missed was to change the return value of object handlers, as those, for the most part, are meant to return zend_result. I didn't push forward with that one as when I realized we were already in beta releases or maybe RC and even changing it for a minor version did feel a bit disruptive. However, it may make sense to tackle this sooner than later if we are doing some other object handler changes. There are however definitely still cases where FAILURE is assumed to be -1 either because this is what the function is expected to return on failure or checking the value of a POSIX like API. Ideally, all cases where zend_result is used would actually indicate this to make it possible to *maybe* convert SUCCESS to true and FAILURE to false and typedef zend_result to bool. Best, George P. Banyard --0000000000007c772105f52154f5--