Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117511 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88399 invoked from network); 11 Apr 2022 12:01:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Apr 2022 12:01:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B20BD180381 for ; Mon, 11 Apr 2022 06:33:10 -0700 (PDT) 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_H2,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-yb1-f181.google.com (mail-yb1-f181.google.com [209.85.219.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 11 Apr 2022 06:33:10 -0700 (PDT) Received: by mail-yb1-f181.google.com with SMTP id t12so6982591ybt.10 for ; Mon, 11 Apr 2022 06:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bQvyYI3v+mElhDX6H1JxF5UBy1uGCttVTYD7Y0ZPs+Q=; b=bs6kHAk2ykYYiI+GsPoUK9u3Gx/m67khjnUzSJyXj+/45ykhKlWS8T6axpFQHeRrQ3 n7XdH66MZkDQeJdLu7BIXt3uKeHHXkyTK+M7gVIf6GdpNLIzQQ7zG7GNku2+mhGXF1/Q J6iz9UDyqpQxSs6eLzTQSc5ynVGu59yuFxjm3y/VSAXcNxUYlFGvyCQLepvXM5hrEIHX 3Ye1nwYnmKnnK5s7+BraL7GKXzZBXZ/FlkNbQhmCVJUHWz5kymocnHiRsQr2BPh89WnE f7nqrjrlB2WFPIn1cIU0yWNaU7hXpeDYt5Ry1KWmXNLLgMGVUkx28JelCcehOKRHi2sb XKaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bQvyYI3v+mElhDX6H1JxF5UBy1uGCttVTYD7Y0ZPs+Q=; b=P/x4BAbizuyDfbDpx4Pf1SK2UAnQjt1ULntxdwGh85+Fh9oPyHj8IH0VejgLme82Oh aCRgiX3NJ5azQgGNEzAsj+0MaNJMDPenltgTdpMIcLwfyZlXFO9f+6nkgY4+Q59ouNzW cM9tWMMzxPsL7KwwIbZ1HLS3Dx3D1pVevMJ7NqC3q0WztDkT7FXxeX9gYlFc52+92SVm ZtHXJs4XSZVP+CXtb8ADIhW3nJLG0iyao0BvWV6uWFLUOD92bzUkhKSd2x7is1jaVtb3 S3D0ndh/IMMoOup2hI+A62sWvSUIyfqh96Cic5gcyn1BNx+FLxjUeK7UbVGa3vOTcCBG mNUA== X-Gm-Message-State: AOAM533W+IXk8JLTnYh2xMs81kJR4J/xg0Q8x1IkS6rJIV7ZniANqzOg TjNstx7PA46y8nhzCjZqwckLxNqLXcqAQK1UMxc= X-Google-Smtp-Source: ABdhPJxEAhIIUokrBoNij0nCjsXN5mUdHX3li2YqVouIjdlSoaF2ZO1bXn4yihmlbRD+AxeH2K/KcnyiDju3UjxzMh8= X-Received: by 2002:a25:344b:0:b0:641:3503:6880 with SMTP id b72-20020a25344b000000b0064135036880mr5947015yba.341.1649683989685; Mon, 11 Apr 2022 06:33:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 11 Apr 2022 14:32:58 +0100 Message-ID: To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000032690805dc60fc13" Subject: Re: [PHP-DEV] [RFC] Add true as type From: george.banyard@gmail.com ("G. P. B.") --00000000000032690805dc60fc13 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sat, 9 Apr 2022 at 12:05, Tim D=C3=BCsterhus wrote: > Hi > > On 4/8/22 18:47, G. P. B. wrote: > > Now that null and false can be used as standalone types, I think it > makes a > > lot of sense to add true as a value type for the sake of completeness > with > > false. > > I agree that it would make sense to have 'true' as the counterpart of > `false` for completeness, but =E2=80=A6 > > > It also has many use cases within internals and userland to declare > proper > > type signatures to functions and methods. > > > =E2=80=A6 seeing the examples of functions that might return `true`, but = won't > return false, I feel like the correct solution is not adding `true` as a > standalone type, but instead making those function return something more > obvious. > > - The `sort()` family should rather be be ': void' which would make it > more obvious to static analysis that '$sorted =3D sort($unsorted)' is not > a correct usage. > - `DiagnoseCommand::checkComposerSchema()` in composer would benefit > from having support for tagged unions, as currently both the error case > (`string`) and the success case (`true`) are truthy. With the current > PHP 8.1 feature set I can imagine that returning a proper bool and > putting the reason in an `string &$reason` reference parameter would > make it more obvious to use this function in an `if ()`. > - `JsonFile::validateSchema()` in composer should be ': void' as errors > appear to be communicated using Exceptions. > - The closure in `ComposerRepository::asyncFetchFile()` would benefit > from having support for tagged unions, but even with the current PHP 8.1 > feature set I can imagine that: > > enum CacheStatus { case Hit; } > > and then making the function `mixed[]|CacheStatus` instead of > `mixed[]|true` would make it more obvious what the meaning of the second > option in the union is. > > Best regards > Tim D=C3=BCsterhus > There are many many many more internal functions in PHP which only return true, but only since PHP 8.0.0, and this is due to the huge amount of E_WARNING to ValueError/TypeError promotion which has happened. These functions previously did return false in certain circumstances, and although I agree that changing these to void *would* be the most ideal, being able to do this communicating that these functions only return true (which means one can ignore the return value) is the first step. Moreover, it is even more of a BC break compared to changing something which only returns false to void as code like: if (always_true(...)){ ... } would stop executing this code path. Not adding true as a type prevents extending methods which return bool to always return true to clearly document this within the typesystem. Best regards, George P. Banyard --00000000000032690805dc60fc13--