Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:120522 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85340 invoked from network); 4 Jun 2023 13:37:36 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Jun 2023 13:37:36 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A016018004D for ; Sun, 4 Jun 2023 06:37:34 -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 06:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1685885852; bh=0aldoyQOa86rct6YxH4PEpcun+RYUa18IiNognURqOQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=evq7becIBYFXNhyJopF0DMnmrnz+3hqmYxethAa9+fcyo5lnpoWXElLvcE64xrOZX WYD3D5jh2c+cOxoPLmgDy4aCv0Kbq9GItVM3oFu4ILEF26Tf0bbVsBJADAfjAcqPyJ EYANgYfuBBDgLaprgIHkNeadwyGFSnhLuxEhs0+K68WbVnLhmyCJvN2XmQmAQJsh0v zePorYGQrDOYJE/TCpwESfhMZ+nf6DXVRNOr3hn1hGUdTdZ8En/aBQoo/pCy2+vw0e kGB1CCS86zJXqHEdeKSUpDtCUimvmsz4J72+J9sAu2w1Txh/CMh5rP1n3KQYuN5xA0 jQ5cuaRaSZhIw== Message-ID: <960b69dc-9892-2964-6067-c024fb66b4fe@bastelstu.be> Date: Sun, 4 Jun 2023 15:37:30 +0200 MIME-Version: 1.0 To: Claude Pache Cc: PHP internals References: <91F5F43D-5A20-4B14-B2D1-475607021940@gmail.com> Content-Language: en-US In-Reply-To: <91F5F43D-5A20-4B14-B2D1-475607021940@gmail.com> 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/29/23 21:34, Claude Pache wrote: > One weakness of the proposal, is that there is no notice when a method without #[\Override] annotation accidentally overrides a parent method. This is necessary for the sake of BC, of course. Therefore, (inspired by the --noImplicitOverride flag of TypeScript), I suggest adding a complementary #[\NoImplicitOverride] annotation on the derived class, that makes #[\Override] mandatory on overriding methods. The following example would then trigger a compilation error since Laravel 5.4: > Thank you for that suggestion. As a solution to that problem only a per-method attribute came to my mind and that clearly does not scale / adds too much visual noise for a very common case. However I'm not sure if a class-level attribute is the right choice either. Contrary to #[\Override] itself, which clearly adds metadata (namely the "intent") to a single method, the #[\NoImplicitOverride] is more of a config flag for the engine behavior, instead of "metadata". It doesn't really belong on the class, the class just happens to be a convenient location. The `declare()` construct however is intended to hold this kind of behavior directives. So `declare(no_implicit_override=1)`, similarly to `declare(strict_types=1)` appears to be the natural solution here. It's not particularly pretty, but would be reasonably consistent with the rest of the language. It would be less forward-compatible (unknown declares emit a Warning), though. I'm also not sure about the impact on the implementation. The support for "no implicit override" would require at least another bit-flag for only a smaller incremental improvement over #[\Override] itself. Best regards Tim Düsterhus