Skip to content

OverrideAttributeWithoutTarget ​

error native on by default PHP ≥ 8.3

Group: Probable bugs

Apply Override to an inherited member.

Example ​

Finding:

php
<?php
class Worker { #[\Override] public function start() {} }

Reported:

  • line 2: Apply Override to an inherited member.

Detection ​

  • Resolve the builtin Override attribute on a method. Report only when the complete parent and interface closure proves there is no overridable method of that name. From PHP 8.5 also check properties against inherited properties; methods and properties are separate lookup domains. A private parent method does not satisfy a method override; abstract interface requirements do.
  • Emit one finding per violating operation. Flow facts require a reachable path with no intervening mutation, escaped alias, unknown call involving the tracked value or analysis-budget exhaustion. Uncertain facts cannot prove a violation.

Exceptions (no report) ​

  • Unknown ancestors or inherited traits prevent a definite missing-target proof. Exclude shadowed custom Override attributes and inaccessible private declarations.
  • Exclude shadowed builtin symbols, unresolved required types, incomplete syntax and unsupported PHP versions.
  • A member declared in a trait is never reported: PHP checks the attribute in each class that uses the trait, against that class's ancestors, so the trait alone proves nothing.
  • A method named __toString (any case) is never reported: declaring it makes the type implicitly implement Stringable, whose __toString is the overridden method.

Fix ​

No automatic fix. Choosing a repair requires runtime information, error-handling policy or a semantic decision.

All edits use exact byte ranges, preserve comments and evaluation order, and require syntax supported by the target PHP version. A fix must never add an evaluation or silently change unrelated arguments.

PHP versions ​

Minimum PHP 8.3.

Configure ​

In custos.json:

json
{
  "rules": {
    "OverrideAttributeWithoutTarget": {
      "enabled": false
    }
  }
}

Suppress ​

Before the statement or declaration (or the first statement of the file):

php
// @custos-ignore OverrideAttributeWithoutTarget

Released under the MIT License. Native rules and rules modeled on Php Inspections (EA Extended); independent clean-room implementation.