8

如果有错误,这是部分。

致命错误:在第 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]}");

非常感谢!欣赏!

4

4 回答 4

15

$this 仅在方法中有意义,在函数中无效

还行吧

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

这不是

function some() {
    $this->

// 编辑:没有注意到他将“$this”作为参数传递

建议:只需将 "$this" 替换为 "$somethingElse"

于 2009-10-29T14:00:00.577 回答
7

您不能传递$this给程序函数。$this是保留变量。

于 2009-10-29T14:01:52.180 回答
5

根据我的评论。您想$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]}");
于 2009-10-29T14:31:04.143 回答
0

您必须先制作对象。

   $object=new Myobject;
   DoEvents($object);
于 2009-10-29T14:21:37.147 回答