views:

939

answers:

4

Hi Friends,

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 is: $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!

+3  A: 

$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"

stereofrog
thanks for reply! this is an opensource softwares code which was working well on PHP4. now i try on PHP5 and has errors :/ I'm not very good at php :/ trying to sort out the issue according to your advise...
artmania
so how can i edit this? :/ if i put a class on top, the other pages are not working... big mess
artmania
wowowowow man!! I LOVE YOU@@@@!!!! LIFE SAVER!!!! THANKS A LOT MAN!! :) )woaaaa so happy!!
artmania
just silly $this issue!!! i name it as $thiss and it works perfect!!
artmania
+3  A: 

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

Jeff Ober
hey, thanks! so what is your advise for solution? can you be a bit more clear? Im not very good at php :/
artmania
just change the name of the variable passed. check my answer.
Michal M
A great gotcha!
David Caunt
Michael is absolutely correct. Just change the name of the variable.
Jeff Ober
A: 

You have to make the object first.

   $object=new Myobject;
   DoEvents($object);
dnagirl
+1  A: 

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]}");
Michal M
yes ! thats the issue! how silly im! sorted just before your comment... you life saver too!! thanks a lot!!! super you guys are!
artmania