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

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

    First you understand one thing, $this inside a class denotes the current object.
    That is which is you are created out side of the class to call class function or variable.

    So when you are calling your class function like foobar::foobarfunc(), object is not created. But inside that function you written return $this->foo(). Now here $this is nothing. Thats why its saying Using $this when not in object context in class.php

    Solutions:

    1. Create a object and call foobarfunc().

    2. Call foo() using class name inside the foobarfunc().

提交回复
热议问题