简体   繁体   English

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

[英]Fatal error: Using $this when not in object context

here is the part if having error. 如果有错误,这是部分。

Fatal error: Using $this when not in object context in /pb_events.php on line 6 致命错误:在第6行的/pb_events.php中不在对象上下文中时使用$ this

line 6 is: $jpp = $this->vars->data["jpp"]; 第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]}");

Thanks a lot! 非常感谢! appreciate! 欣赏!

$this only makes sense in methods, not in functions $这只在方法中有意义,而不是在函数中

this is ok 还行吧

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

this is not 这不是

function some() {
    $this->

// edit: didn't notice he passes "$this" as parameter //编辑:没有注意到他将“$ this”作为参数传递

advice: simply replace "$this" with "$somethingElse" 建议:简单地用“$ somethingElse”替换“$ this”

You cannot pass $this to a procedural function. 你不能将$this传递给程序函数。 $this is a reserved variable. $this是一个保留变量。

As per my comments. 根据我的评论。 You want to use $this as passed variable and php doesn't allow it outside class methods body. 你想使用$this作为传递变量而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]}");

You have to make the object first. 你必须先把对象做好。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM