Do I understand correctly setting $this?

Good afternoon/evening. I started to learn PHP OOP and have encountered a misunderstanding himself. Seem to understand and don't understand the variable $this.

Please view the simple code and tell me if I understand correctly setting $this?
class worker {

 //Set the default variable values
 public $name = "Name";
 public $balance = "Balance";
 public $savings = "Salary";
 public $profession = "Profession";
 public $income = "Income";
 public $despense = "Expense";

 /*Create the design for the object*/

 //Set the design parameters that need to be changed when the method invocation
 function __construct ($name, $balance, $savings, $profession, $income, $despense) {

 //Turn to the variable $name is assigned the default value from the worker class
 $this->name = $name;
 $this->balance = $balance;
 $this->savings = $savings;
 $this->profession = $profession;
 $this->income = $income;
 $this->despense = $despense;
}
}

/*Create a variable $worker2, and assign the worker object
 *Specify data for the parameters*/
$worker2 = new worker("Ghost", 5000, 535000, "CIA special Agent", 44223493, 20330);

//Output data 
echo "Name: ".$worker2->name."<br>";
echo "Balance: ".$worker2->balance." RUB.<br>";
echo "Salary: ".$worker2->savings." RUB.<br>";
echo "Job: ".$worker2->profession."<br>";
echo "Income: ".$worker2->income." RUB.<br>";
echo "Coverage: ".$worker2->despense." RUB.<br>";
July 2nd 19 at 13:31
3 answers
July 2nd 19 at 13:33
Solution
$this refers to the current instance of the class.
Code $this->name = $name; sets the name parameter from the current instance of the object, the value of $name.
Visually the code looks correct, except that it is better to learn to call things by their names - __construct is the constructor and not design)

Well, just in case php.net/manual/ru/language.oop5.basic.php
Thanks for the reply and the link. - Albertha.Tremblay commented on July 2nd 19 at 13:36
July 2nd 19 at 13:35
Solution
Using $this you can/need to access the variables and methods inside a class. It's all right.

But one point confuses me. Why set a variable default value if the object's constructor, they still definitely will be rewritten... it doesn't make much sense, except for very rare situations, but I think this is not the case.
I also started thinking about this.
Thank you for your comment, and sorry for the bad code. Literally the first day I sat down for PHP and understand OOP (somehow more sympathetic than procedural). - Albertha.Tremblay commented on July 2nd 19 at 13:38
: in addition to procedural and OOP there is still at least several, for example mandatory :) - Albertha.Tremblay commented on July 2nd 19 at 13:41
: or empirical :D - mohamed.Muller commented on July 2nd 19 at 13:44
: I still OOP want to learn, then look at the advantages and disadvantages of others. - Salvado commented on July 2nd 19 at 13:47
July 2nd 19 at 13:37
Solution
While $this is all true. Read the difference between self: and $this. It will be clear.
Everything I want to add is not so much to do:
function ....($name, $balance, $savings, $profession, $income, $despense)

I understand you create an object with many properties and set them using the enumeration method. Don't do that - through multiple listing in the method. And if tomorrow the properties will be 10000?
So you need to:
$object = new Object();
$object->param = "value";
....
I agree with your opinion, and thanks for the tip with self - Albertha.Tremblay commented on July 2nd 19 at 13:40

Find more questions by tags PHPOOP