Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117513 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91956 invoked from network); 11 Apr 2022 12:28:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Apr 2022 12:28:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2400A180510 for ; Mon, 11 Apr 2022 06:59:51 -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=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 11 Apr 2022 06:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1649685587; bh=OiI7/YenlAgEmAIWpjoOmc7NighQPEyxPdE/h/hJ4ss=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=fiQXNmHtym/beeZTMNFJxlapDvznN9TfgNqaEWWbgnHsFBF05v7qBM74xzHE9yKNT gWQ0ZVg11GPNb/6Zhe/lAD7L5BfabRWB7fG/nfSxy2eIkS8RilSIb6kpf6+sB3sXwE jMbfjNsQa5VASSONOWlSBR3AKViGXWsyBuqbBlShAVNinDYP6fxkGDbj71CguGPoU/ U8uJcNtAbc6XRG/Z1d8dg3shmoSdoyH4PGF1jas5se24XmwJEm8VIlqDmFYwhp3Zez RfYXhloXL+sVdRxD58mZc8qtKpTFt3mSzyM9k+CrzjlKd/s343FQ+frlBhnccevqWv 7r0KN2PwMXGMA== Message-ID: Date: Mon, 11 Apr 2022 15:59:45 +0200 MIME-Version: 1.0 Content-Language: en-US To: "G. P. B." Cc: PHP internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Add true as type From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 4/11/22 15:32, G. P. B. wrote: > 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 I see. I think you should clarify this in the "Examples" section, that (some of) these functions previously were an actual `: bool` instead of `: true`. > 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. I was not attempting to argue that the return type should be changed to `: void` (because of the obvious BC issues). Instead I believe that probably would choose an entirely different return type if the functions would be newly introduced. > Not adding true as a type prevents extending methods which return bool to > always return true to clearly document this within the typesystem. This argument was also used for allowing `null` / `false` as a standalone type, because there is no good reason to allow `null` / `false` in a union type, but not standalone. For `true` the story is different, as this type is an entirely new type available to userland and by the same argument one could have literal strings or literal integers as distinct types as well. I wouldn't object to that per se (and there's precedent in TypeScript), but there could be a clearer plan for the type system as a whole, instead of adding types piecemeal. I *can* see the value in having `true` for completeness, though. Best regards Tim Düsterhus