Skip to content
Daily Dev Tip

This tip lives in your new tab — for free.

Install for Chrome →
PHP

Add #[\Override] in PHP 8.3 to catch broken method overrides at compile time

app/Services/BaseService.php
php
class BaseService
{
    protected function handle(): void {}
}

class ReportService extends BaseService
{
    #[\Override]
    protected function handle(): void
    {
        // If the parent renames or removes handle(),
        // this now fails at compile time instead of silently
        // becoming a new, never-called method.
    }
}

`#[\Override]` (PHP 8.3) tells the engine you intend to override a parent or interface method. If no matching method exists — because of a typo, a signature change, or a parent refactor — you get a compile-time error instead of a silent no-op method that never runs. It's cheap insurance on any class hierarchy, and it documents intent for the next reader.

php8.3attributesinheritancesafety