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.
This error is also reported when creating a closure from a non-static method. This happen even if the method is not actually called.
Example¶
<?php
class X {
static function foo() {
//Non-static method x::foo() cannot be called statically
self::goo();
}
function goo() {}
}
(new X)->foo();
// when creating a closure
$closure = X::goo(...);
?>
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.
Static Analysis¶
This error may be tracked down with the following static analysis rules: Classes/NonStaticMethodsCalledStatic.