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

后端 未结 9 2363
日久生厌
日久生厌 2020-11-22 03:48

I\'ve got a problem:

I\'m writing a new WebApp without a Framework.

In my index.php I\'m using: require_once(\'load.php\');

9条回答
  •  一整个雨季
    2020-11-22 04:29

    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
    $foobar->foobarfunc();
    

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

    foobar::foobarfunc();
    

    You should instead use:

    foobar->foobarfunc();
    

    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:

    foobar::foobarfunc();
    

提交回复
热议问题