Code Inspection: Dynamic method called as static
Reports static calls to dynamic class methods.
For classes having the magic method __callStatic
, a separate inspection severity and highlighting level can be set.
In PHP 5.6 and later, calling static methods dynamically is deprecated and generates an E_DEPRECATED
warning. As of PHP 7.0, calling a non-static method statically results in $this
being undefined inside the method. See OOP Basics (php.net) for details.
In the following example, the method foo()
is called as static while actually it is dynamic.
class A
{
public function foo() {
}
}
$a = new A();
$a::foo();
Suppress an inspection in the editor
Position the caret at the highlighted line and press Alt+Enter or click .
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.
Last modified: 16 July 2021