致命错误:当不在对象上下文中时使用$ this

这里是错误的部分。

致命错误:在不在第6行的/pb_events.php中的对象上下文中时使用$ this

第6行是: $jpp = $this->vars->data["jpp"];

 function DoEvents($this) { global $_CONF, $_PAGE, $_TSM , $base; $jpp = $this->vars->data["jpp"]; $cache["departments"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_departments]}"); $cache["locations"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_location]}"); $cache["names"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_names]}"); $cache["categories"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_categories]}"); 

非常感谢! 欣赏!

$这只适用于方法,不适用于函数

还行吧

 class Foo { function bar() { $this->... 

这不是

 function some() { $this-> 

//编辑:没有注意到他通过“$ this”作为参数

build议:只需将“$ this”replace为“$ somethingElse”

您不能将$this传递给程序函数。 $this是一个保留的variables。

根据我的意见。 你想使用$this作为传递variables,而php不允许在类方法体外使用。

 function DoEvents($obj) { global $_CONF, $_PAGE, $_TSM , $base; $jpp = $obj->vars->data["jpp"]; $cache["departments"] = $obj->db->QFetchRowArray("SELECT * FROM {$obj->tables[job_departments]}"); $cache["locations"] = $obj->db->QFetchRowArray("SELECT * FROM {$obj->tables[job_location]}"); $cache["names"] = $obj->db->QFetchRowArray("SELECT * FROM {$obj->tables[job_names]}"); $cache["categories"] = $obj->db->QFetchRowArray("SELECT * FROM {$obj->tables[job_categories]}"); 

您必须首先制作对象。

  $object=new Myobject; DoEvents($object);