>>1
This is PHP.
Regarding
$this ->
$this is a predefined variable of every instance of any object in PHP and most OO languages will have something equivalent (cf "this" keyword in java etc..)
It simply behaves like a pointer to an object, namely itself; so you can treat it like a local variable of whatever type the class is; that contains a reference to itself.
Notice that all member variables of $this are the local varaibles of that object, variables of functions cannot be referenced by $this because they are not actual fields of the object but belong to the function call instead. Thus, a key usage for the $this variable is differentiating between two variables of the same name, where one is local to a method and one is a field of the object as is visible in your example. Sometimes in a poorly designed system $this can also be a quick hack to fix something that would of otherwise required a redesign; where there is a circular dependency and some created objects need to know what object instantiated them you could use
Object obj = new Object(this)
Some languages will also allow the use of this() as a method/function. This esentially calls its own constructor as a method, and allows for overloaded constructors and other bits and peices. ex:
public class Jew {
private int jewness;
private ConcentrationCamp home;
private boolean gassed;
private Jew(ConcentrationCamp home, boolean gassed, int jewness) {
this.home = home;
this.gassed = gassed;
this.jewness = jewness;
}
public Jew(boolean gassed) {
this(ConcentrationCamp.AUSCHWITZ, gassed, 100);
}
public Jew() {
this(true);
}
}