我有一个问题:
我正在写一个没有框架的新WebApp。
在我的index.php我使用:require_once(‘load.php’);
在load.php我使用require_once(‘class.php’);加载我的class.php。
在我的class.php我有这个错误:
Fatal error: Using $this when not in object context in class.php on line … (in this example it would be 11)
我的class.php写的一个例子:
class foobar {
public $foo;
public function __construct() {
global $foo;
$this->foo = $foo;
}
public function foobarfunc() {
return $this->foo();
}
public function foo() {
return $this->foo;
}
}
在我的index.php我加载也许foobarfunc()像这样:
foobar::foobarfunc();
但也可以
$foobar = new foobar;
$foobar->foobarfunc();
为什么会出现错误?