Re: RFC [Discussion]: Marking overridden methods (#[\Override])

From: Date: Mon, 29 May 2023 19:34:21 +0000
Subject: Re: RFC [Discussion]: Marking overridden methods (#[\Override])
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-120438@lists.php.net to get a copy of this message
> Le 11 mai 2023 à 18:37, Tim Düsterhus <tim@bastelstu.be> a écrit : > > Hi > > I'm now opening discussion for the RFC "Marking overridden methods > (#[\Override])": > > ---- > > RFC: Marking overridden methods (#[\Override]) > https://wiki.php.net/rfc/marking_overriden_methods > Hi Tim, 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: <?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Http; #[\NoImplicitOverride] // <====== HERE class RssFeed extends Model { /* Laravel 5.4 added the refresh() method to Eloquent, but we already * have a custom method with the same name and signature that does * something entirely different. */ public function refresh() { $this->message = Http::get($this->url); $this->save(); } } ?> ―Claude

« previous php.internals (#120438) next »