PHP

PHP

Made by DeepSource

Abstract method defined in a non-abstract class PHP-E1115

Bug risk
Critical

One or more abstract methods have been defined in a class that is not abstract. Declaring abstract methods are only supported inside an abstract class.

An abstract class is a superclass which provides a blueprint for derived classes and set some rules what the derived classes must implement when they inherit an abstract class.

To fix this issue, either declare the class as abstract or drop the abstract keyword from the method.

Bad practice

class User
{
    // invalid: non-abstract class `User` can't declare abstract method
    abstract public function getName(): string;
}

Recommended

Declare class as an abstract:

abstract class User
{
    abstract public function getName(): string;
}

Or, make sure abstract methods are not declared inside non-abstract class:

class User
{
    public function getName(): string
    {
    }
}

References