> Le 11 mai 2023 à 18:37, Tim Düsterhus <t...@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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php