Fatal error: Using $this when not in object context in PHP

Fatal error: Using $this when not in object context in PHP

Whenever you got this error check the following:

1. Make sure the $this-> is used inside the object and referring to the class’s and inherited non-static members.

2. Make sure the called members of the object are properly addressed as static or member/function variables

Do you know the different different post types?

Here is an example for the second one.

Assume you have the following object


class Example
{
   function getExampleText()
   {
      return "Example Text";
   }
   static function getStaticExampleText()
   {
      return "Static Example Text";
   }
}

While accessing, if the code tries something like this one,

$example = new Example();
Example::getExampleText(); //Trying to access non-static as static

Then you would have the error

The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path

Add batch/multiple posts to Facebook Page – Graph API

Using Facebook API to post articles from PHP

AbstractSureFireMojo Class Missing Maven Surefire

Spring Data error: getOutputStream() has already been called for this response

Post to Facebook From app – Using PHP

2 Comments
  1. legendarynoob

    I’d really love to learn php, mysql, etc. But it’s things like this that frustrate me… I’ve been running a WordPress Blog fine for months…then all of sudden with no warning or no changes I get this error message?!! How does that happen?

  2. gullele

    Hi legendarynoob,
    I really appreciate for reading my blog and put your comment/question.
    I would encourage you to learn php and mysql because it is too easy to learn but very effective for real time web development. Of course, just like every other discipline, it has its own learning curve – it is during that you might get some weird things.
    If you were running everything perfect on WordPress and all of a sudden it got that message, some internal functionalities might be changed or it could be something from your side. If you give me a detailed error that you got and the event that triggered it, I might try to help.
    Thanks again

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*