website/errors/method.override.md
<?php declare(strict_types = 1);
class Foo
{
#[\Override]
public function doSomething(): void
{
}
}
A method has the #[\Override] attribute, but it does not actually override any method from a parent class or implemented interface. The #[\Override] attribute (introduced in PHP 8.3) is meant to signal that a method is intentionally overriding a parent method. If no parent method exists, the attribute is incorrect and the error is reported to help catch typos in method names or incorrect class hierarchies.
Remove the #[\Override] attribute if the method is not intended to override a parent method, or fix the class hierarchy so that the parent method exists.
<?php declare(strict_types = 1);
class Foo
{
- #[\Override]
public function doSomething(): void
{
}
}
Or ensure the class extends the correct parent:
<?php declare(strict_types = 1);
-class Foo
+class Foo extends Bar
{
#[\Override]
public function doSomething(): void
{
}
}