我不断收到此错误PHP致命错误:使用$ this而不是在对象上下文中我无法为我的生活找出原因。是否有另一组眼睛可以提供帮助?我有另外一个班级设置类似,并没有抛出错误。代码如下(为了便于阅读,向下撇取):
include '< const class id >.php';
class ParseFunctions {
private $_id = '';
public function __construct(){
$id = new IDS;
$this->_id = $id::<const class id>;
}
public function set_id(){
$new_id = $this->id; <--- this line throws the error
$print_r($new_id);
}
}
任何帮助表示赞赏!谢谢!
'$ this-> id'不存在。它应该是'$ this - > _ id'吗? – 2013-06-28 23:07:13
与此问题无关,但这是一个奇怪的外观,因为您没有传递参数。你能告诉你如何调用'set_id()'吗?如果你试图在静态上下文中调用,那会导致这个错误。 –
id/_id的东西不应该导致这个错误。 说实话,这个错误的本质是这样的,除非我们看到set_id()被调用,否则很难提供帮助。我的猜测是你在某处静态地调用set_id(例如:: set_id()而不是 - > set_id()) –