1.2.16. Abstract Static Methods

Methods cannot be both abstract and static. Static methods belong to a class, and will not be overridden by the child class. For normal methods, PHP will start at the object level, then go up the hierarchy to find the method. With static, it is necessary to mention the name, or use Late Static Binding, with self or static. Hence, it is useless to have an abstract static method : it should be a static method.

A child class is able to declare a method with the same name than a static method in the parent, but those two methods will stay independent.

This is not the case anymore in PHP 7.0+.

<?php

abstract class foo {
    // This is not possible
    static abstract function bar() ;
}

?>

See also Why does PHP 5.2+ disallow abstract static class methods?.

1.2.16.1. Suggestions

  • Remove abstract keyword from the method

  • Remove static keyword from the method

  • Remove the method

1.2.16.2. Specs

Short name

Classes/AbstractStatic

Rulesets

All, Analyze, Changed Behavior

Exakat since

0.8.4

PHP Version

With PHP 7.0 and older

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

method, abstract, constant

Available in

Entreprise Edition, Exakat Cloud