Non-static method %s::%s() cannot be called statically

Description

While a non-static method can call a static method, the contrary is not possible. In particular, the non-static method will not be able to have a valid $this variable, since the static call doesn’t provide one.

Example

<?php

class X {
    static function foo() {
        //Non-static method x::foo() cannot be called statically
        self::goo();
    }

    function goo() {}
}

(new X)->foo();

?>

Literal Examples

  • Non-static method x::foo() cannot be called statically

Solutions

  • Make the concrete method static too.

  • Find an object to call the non-static method.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See nonStaticMethodCalledStatically.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See nonStaticMethodCalledStatically.

Static Analysis

This error may be tracked down with the following static analysis rules: Classes/NonStaticMethodsCalledStatic.