4 Replies - 779 Views - Last Post: 04 June 2012 - 05:56 PM Rate Topic: -----

#1 skirkpatrick  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 18-February 08

Fatal error: Using $this when not in object context in /var/www/h

Posted 04 June 2012 - 11:24 AM

I have an application I am writing where on most pages there is an $this->data value. I am also using an include() to fetch a globalVar.php which isolates changes to the code based on the URL of the page. But On simple pages - say a password reminder page which does not contain a $this->data value it throws this error.

$this->data['parts']['testL'][0][0] = str_replace("test1", "", $this->data['parts']['testL'][0][0]);



Can anyone tell me how to get around the error.

Thanks in advance,

Steve

Is This A Good Question/Topic? 0
  • +

Replies To: Fatal error: Using $this when not in object context in /var/www/h

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: Fatal error: Using $this when not in object context in /var/www/h

Posted 04 June 2012 - 11:29 AM

is_object()?
Was This Post Helpful? 1
  • +
  • -

#3 skirkpatrick  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 64
  • Joined: 18-February 08

Re: Fatal error: Using $this when not in object context in /var/www/h

Posted 04 June 2012 - 02:00 PM

Thanks for the reply - I was not able to get that to work. I was able to limit that code to just certain pages.

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: Fatal error: Using $this when not in object context in /var/www/h

Posted 04 June 2012 - 02:32 PM

So something like

if (is_object($this) && isset($this->data, $this->data['parts'])) {
    $this->data['parts']['testL'][0][0] = str_replace("test1", "", $this->data['parts']['testL'][0][0]);
}



didn't prevent the error?
Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2895
  • View blog
  • Posts: 10,027
  • Joined: 08-August 08

Re: Fatal error: Using $this when not in object context in /var/www/h

Posted 04 June 2012 - 05:56 PM

I'm confused. You say you're writing it, but it has multiple instances of "$this->" in it and you don't know why you sometimes get an error. Do you know what an object is, or why you would use "$this->"?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1