Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120524 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90192 invoked from network); 4 Jun 2023 14:12:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Jun 2023 14:12:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0265C1804D0 for ; Sun, 4 Jun 2023 07:12:32 -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,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 ; Sun, 4 Jun 2023 07:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1685887950; bh=/T2LrwWv1doAENiicxRYz8o7kzQVAG543yihjryIEZc=; h=Message-ID:Date:MIME-Version:Subject:To:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=ijxLq3RFXcdebItvKq6lQ4DmO9vgr9DyEc29FDAsbwlzBSdgb6hWsiAkvaqnd3X3t AFJjaEoZOhLGVfeEMrPzxj9rL7cfX/bBx7tCKMwXQSEbHDeMKQ+FX7G1VWoM7e6YLk DSf4ZYzhSYOtpgP8KJs9CCuVMffr2GJJ6p6M0lAnG7z/VbKeX25pTVs335Cc8OgpVe 1X1D3X2LfpfLQZL2XOdUVYRoYfSKYQ36YqCXu/fFPP2kBR90kKgXwQnTkPaP8II7xa U/gP+3QDWTwyXOmI2ZVW3kWqxmzk//KrULu2VZ0vsP0ve/HmNuYrRQDdnSqA3IRRq6 vm8GyqGk3LVpg== Message-ID: <91622930-384c-d72d-0e62-eb438266d588@bastelstu.be> Date: Sun, 4 Jun 2023 16:12:29 +0200 MIME-Version: 1.0 Content-Language: en-US To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC [Discussion]: Marking overridden methods (#[\Override]) From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 5/30/23 14:17, Rowan Tommins wrote: > On 29/05/2023 19:29, Tim Düsterhus wrote: >> I think this is a flawed premise: Any sort of analysis that PHP itself >> performs can also be performed in userland. > > > This isn't actually true. There is a lot of dynamic functionality in PHP > where correctness can't be proven ahead of time, and run-time checks are > the only way. That's why Hack evolved away from being a superset of PHP > to being a related but incompatible language, and why languages like > Dart continue to include run-time type checks despite mandatory > pre-compilation analysis. > Fair enough. Main point still stands, though. LSP checks or other type checks wouldn't technically be necessary in PHP itself. As with "duck typing" the runtime check at the last possible moment (e.g. the actual method call) would catch the mistake, however it would catch it much much later, once the broken data made it halfway through the application. These type checks are effectively (re)implemented in userland and are even more powerful, due to the support for generics / typed arrays. Nonetheless having them in the language provides a clear benefit, because they are always available and thus compatible, no matter which choices the other developer of a library made with regard to static analysis. >> It's part of the language and thus will *always* be available. If it's >> not always available, then folks who switch jobs or contribute to >> various open source projects that made a different choice with regard >> to analyzers will possibly: >> >> - Be unable to rely on a specific check that they found useful in the >> past, because the new SA tool doesn't implement it. >> - Be unable to rely on a specific check working as they learned it, >> because the new SA tool implements it differently. > > > This is a reasonable argument, but it basically comes down to PHP > Internals becoming the controller of a standardised set of static > analysis attributes, because a lot of the functionality will still only > exist in each of those tools. In this specific case of #[\Override] the main functionality is fully available with "just PHP itself". The reverse check that the attribute is used wherever possible is pushed to the userland analyzers / IDEs for now. It would be possible to include it in PHP itself, if we can agree on a reasonable solution to "configure it" (see my email in response to Claude). I'm not sure if I would agree on a standardized set of attributes if PHP itself would not be able to make use of it, because the value of documenting it in the PHP manual would not exist. Developers would need to download one of many third party tools to make use of it. >> As the proposal is a compile time check, the mistake would also be >> immediately apparent just by loading the class (e.g. as part of *any* >> kind of test), it is not necessary to actually execute the method in >> question. So it should be sufficiently visible and usable even in >> codebases that are in a less-than-stellar state. > > > The reason I'm so skeptical of this feature is that the category of > mistake the engine would be able to catch seems like it would be rather > rare. And I really do think it makes a difference that the author of the > *inheriting* class is the only one that can trigger the check. It's anecdata, but the attribute would have saved me debugging effort several times in the past year - that's the whole reason I'm proposing it. It also saved me time in other language that have the feature already built-in. > Users of Guzzle won't see any impact from the Guzzle code base adding > those attributes; they would have to add them to their own code > separately. If they are not using any kind of static analysis tools, > they will not be reminded to add them. They will then only see a benefit > from remembering to add them in the rare case that a parent class > removes a method they were previously overriding. As mentioned before with my own Java experience, I believe that having this kind of feature in the language itself will naturally help its adoption. It will start to appear in codebases, developers will learn about its existence by looking at the code. It will likely also be included in PHP tutorials targeted at developers that learn PHP. Speaking from my own experience with languages that have this kind of feature, it is not something that I "need to remember to add". It becomes a natural part of creating a new method, just like adding parameter types and return types became a natural part of it. > It all seems rather a small niche for the engine to care about, unless > it's the beginning of a larger project to standardise and encourage such > attributes. Best regards Tim Düsterhus