为什么我会收到错误:“不在对象上下文中使用$this.....".


Why do I get the error: "Using $this when not in object context in.........."

$title = 'question' ;)提前谢谢,我似乎想不通。

class myClass {
    public $myVar = 'hello';
    public function myMethod() {
        echo $this->myVar;
    }
}

你在做什么:

myClass::myMethod();

或:

$foo = new myClass();
$foo->myMethod();