PHP help, trying to understand $this and classes?

  • Thread starter Thread starter Dane_62
  • Start date Start date
D

Dane_62

Guest
I'm working on a site that I did not originally program. I'm new to working with PHP classes.

There is a class on this website called Reporting and an extension called main. An instance of main (called $main) is created in the index page (all other pages are an include of the index page). I can't find any place that an instance of reporting is created.

What confuses me is from what I've read, it's my understanding, in order to access a class you must create an instance of that class like this

$main = new main()

Then you can reference aspects of main like this

$main->displaypage()

However there are places all over the code for this site where functions and variables in the reporting class are referenced using a variable called $this, like this

$this->set_value("type",$_POST['type']);

from what I can tell $this is a special variable intended to be used within the class it's self to reference things within the class.

So why do I see this variable outside of the class?
Is this correct syntax?
Any explanation for what's going on here?
Everything seems to work correctly are there in any pitfalls to using $this like that?
 
Back
Top