PHP

PHP

Made by DeepSource

Abstract method has definition PHP-E1118

Bug risk
Critical

Abstract methods should not have a definition. They are used to define a contract that derived classes must implement. Therefore implementing an abstract method itself violates the meaning of defining the method as abstract.

It is recommended to get rid of the body from the abstract method. Or, if you want to implement the method, drop the abstract keyword.

Bad practice

abstract class User
{
    abstract public function setUser(string $name): void
    {
    }
}

Recommended

Either remove the body:

abstract class User
{
    abstract public function setUser(string $name): void;
}

Or, do not define it as abstract:

abstract class User
{
    public function setUser(string $name): void
    {
    }
}

References