Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

Description

A non-static method requires an object to be called, as PHP will populate that object in the $this method.

If the method makes no use of $this, make it static to allow the call. Otherwise, keep it non-static, and use an object for the call.

Example

<?php

class X {
	function foo() { echo __METHOD__;}
}

X::foo();

?>

Literal Examples

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

Alternatives

  • Make the method static.
  • Find an object to call the method.

In more recent PHP versions, this error message is now :ref:non-static-method-%s::%s()-cannot-be-called-statically.