PhpStorm 2020.3 Help

Code Inspection: Method may be 'static'

Reports the methods that don't use any instance references and thus may be converted to static methods.

Static methods normally belong to utility classes and are accessed in the context of a class rather than an object. In the following example, the foo method does not use any instance references, and can therefore be declared as static.

class A { public function foo() { return true; } public function bar() { echo $this->foo(); } } $a = new A; $a->foo();
class A { public static function foo() { return true; } public function bar() { echo A::foo(); } } $a = new A; A::foo();

Suppress an inspection in the editor

  1. Position the caret at the highlighted line and press Alt+Enter or click the Intention action icon.

  2. Click the arrow next to the inspection you want to suppress and select the necessary suppress action.

Last modified: 08 December 2020