Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117506 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41763 invoked from network); 9 Apr 2022 09:34:44 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Apr 2022 09:34:44 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1F3651804CF for ; Sat, 9 Apr 2022 04:05:42 -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 ; Sat, 9 Apr 2022 04:05:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1649502339; bh=Asy+T/VCfifRVOFATYBEsa6b4ThxD2WtX8z1YhuNcpA=; h=Date:Subject:To:References:From:In-Reply-To:From; b=FaeMm2UR1kD5xQk3P7Zczz0IxRX3o7bCtT3KxUSAwiFrZQv7GolGhzuDpoAhjQcM+ UCVabrD1iOKFUxHIojmQA//4S6k0BEZP8KclntnJkwpGdtvcH3wng0GBdOEmamxhD/ m0qAR61s8vEy1mb4Bc0r0shbeqGw72EqQFV/0yyjZKpDN35LWk03oRVGq7K/QhnpsU sLzPyeQZeUQDtvi3gBclZACXJ55oG4jYf+bQm7EKR/CTHiX6S3RbCvkSRQ5SRTKtW/ HuPi85t4ucGMKMwiWrqkl2b+q9jS1Lq5JVNnALJ27LxzHogEY5vWd/6fDpcd8lp0V7 uqPLF7MzX40SQ== Message-ID: Date: Sat, 9 Apr 2022 13:05:37 +0200 MIME-Version: 1.0 Content-Language: en-US To: "G. P. B." , 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/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 … > It also has many use cases within internals and userland to declare proper > type signatures to functions and methods. > … 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 = 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üsterhus