PHP Fatal error: Using $this when not in object context

In my index.php I’m loading maybe foobarfunc() like this:

 foobar::foobarfunc();  // Wrong, it is not static method

but can also be

$foobar = new foobar;  // correct

You can not invoke method this way because it is not static method.


You should instead use:


If however you have created a static method something like:

static $foo; // your top variable set as static

public static function foo() {
    return self::$foo;

then you can use this:


Leave a Comment