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

后端 未结 9 2372
日久生厌
日久生厌 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:12

    It seems to me to be a bug in PHP. The error

    'Fatal error: Uncaught Error: Using $this when not in object context in'

    appears in the function using $this, but the error is that the calling function is using non-static function as a static. I.e:

    Class_Name
    {
        function foo()
        {
            $this->do_something(); // The error appears there.
        }
        function do_something()
        {
            ///
        }
    }
    

    While the error is here:

    Class_Name::foo();
    

提交回复
热议问题