Does anyone have a good example of the user class?

Need a good example/advice for the implementation of the user class, if you have experienced this - please help
April 19th 20 at 12:37
2 answers
April 19th 20 at 12:39
class User
{
 private int $id;
 private string $name;

 public function __construct(int $id, string $name)
{
 $this->id = $id;
 $this->name = $name;
}

 public function getId(): int
{
 return $this->id;
}

 public function getName(): string
{
 return $this->name;
}

 public function rename(string $name): void
{
 $this->name = $name;
}
}


Well it seems so it is the rules class user...
rename? Not changeName? Well it I so, carp) - bridie82 commented on April 19th 20 at 12:42
@bridie82and rename something different from chageName? - rebekah.Cassin commented on April 19th 20 at 12:45
April 19th 20 at 12:41
First you need to answer the question - why do you class user.
If you just "Schaub Bulo", no class you don't need. Don't use arrays.

When you understand why you need classes at all - then be and understanding how to make the user class.
And there - 5 years in 5 minutes to slip will not work.
And by the way there's a good chance neither in 5 or 10 years, the understanding will not come. Out of a hundred users pochapsky well if master three object-oriented programming. It's not terrible, PHP - democratic language, you can write OOP, you scribbled procedureo.

Only in the latter case, do not try to deceive ourselves and sculpt classes from manure and straw, as did the Papuans after the war (during the war from the sky flew a large iron pieces, and brought a bunch of Goodies. Then no white men or pieces and gig was over. Papuans began to build whole airfields with aircraft, hangars, gas station attendants - all made of sticks and straw, in the hope that the sky will appear again on. narabotalo). Because if you do a plane with no real understanding of how it works, then it will not fly. And will only vneshne resemble real.

Find more questions by tags PHP