我有一个问题:
我正在编写一个没有框架的新WebApp.
在我的index.php我正在使用:require_once('load.php');
在load.php中,我require_once('class.php');用来加载我的class.php.
在我的class.php中,我遇到了这个错误:
致命错误:当不在class.php中的对象上下文中时使用$ this ...(在这个例子中它将是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;
}
}
Run Code Online (Sandbox Code Playgroud)
在我的index.php中我加载可能foobarfunc()是这样的:
foobar::foobarfunc();
Run Code Online (Sandbox Code Playgroud)
但也可以
$foobar = new foobar;
$foobar->foobarfunc();
Run Code Online (Sandbox Code Playgroud)
为什么会出现错误?