Fatal error: Using $this when not in object context

前端 未结 4 710
广开言路
广开言路 2020-11-28 15:43

here is the part if having error.

Fatal error: Using $this when not in object context in /pb_events.php on line 6

line 6 i

相关标签:
4条回答
  • 2020-11-28 16:26

    $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

    advice: simply replace "$this" with "$somethingElse"

    0 讨论(0)
  • 2020-11-28 16:39

    You cannot pass $this to a procedural function. $this is a reserved variable.

    0 讨论(0)
  • 2020-11-28 16:39

    As per my comments. You want to use $this as passed variable and php doesn't allow it outside class methods body.

    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]}");
    
    0 讨论(0)
  • 2020-11-28 16:43

    You have to make the object first.

       $object=new Myobject;
       DoEvents($object);
    
    0 讨论(0)
提交回复
热议问题