Jump to content

$this variable


tarlejh

Recommended Posts

btherl's reply brings up some interesting aspects, but I thought I'd expand purely on the question of $this.

 

A class is like DNA.  It's not a thing yet, but it's the blueprint for the thing.

 

You make an object using the "new" keyword.

 

$myFoo = new Foo();

 

So the question in regards to what $this-> does inside class code, is that it represents "this object", allowing you to refer to its variables and methods.  At runtime the values will reflect the object that was created by new.  Of course you can have many Foo() objects, each with its own properties.

 

 

Link to comment
https://forums.phpfreaks.com/topic/229443-this-variable/#findComment-1182211
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.