$this is not required but seen as a good practise to call on class wide or function wide variables within a class. It makes reading the code a lot smoother as you quickly can see and understand the code.
so it's basically like this:
$new_name = "Ben";
$this->name = $new_name;
$this->name is in other words a variable called $name within that class. So assigning $new_name's value to $name is what happened there.
Now for you to understand it better let's assume you have a class called Persons for let say a phone book, and you use the class Person to store details about these persons. So you would preferably want to store a new person, and access its details.
Class Persons {
private $name; // Variable that can only be accessed from within the Person class.
private $phoneNbr; // -||-
Function __Construct($personName, $personPhNbr ) {
$this->name = $personName; // Assign the value from the attribute to the class variable $name
$this->phoneNbr = $personPhNbr;
}
Public Function getName() {
return $this->name;
}
Public Function getNbr() {
return $this-phoneNbr;
}
}
// add a person by creating a new object
$p = new Person("John", "1234");
// displaying the name of the person stored in the object $p is reffering to
echo $p->getName();
// displaying the phone number of the person stored in the object $p is reffering to
echo $p->getNbr();Now you have a nice way of adding persons and getting the info required. So you could now create an array where each element points to a Person class, and you have a nice organised and clean code.
the "arrow" between the variable is just a pointer like in most OOP languages, in java it would be a dot but PHP have chosen to go with the arrow instead. In simple terms it says;
$p which is pointing/reffering to an object of type Person, Access the function with that name in that object.