我有个问题:
我正在写一个没有框架的新网络apply.
在我使用的index.php中:require_once('load.php');
在load.php中,我用require_once('class.php');
来加载我的class.php.
在我的class.php美元里,我有这个错误:
致命错误:在class.php行上不在对象上下文中时使用$this.(在本例中为11)
my 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();
为什么会出现错误?