Avatar ·

When to use self and when to use $this in PHP? Difference and examples

Hello everyone! I started learning OOP in PHP and can't understand the difference between `self` and `$this`. Both seem to be used inside a class to access properties and methods, but I keep getting confused. Here's an example of my code: ```php class User { public $name = 'Guest'; public static $count = 0; public function setName($name) { $this->name = $name; // why not self? } public static function getCount() { return self::$count; // why not $this? } } ``` When I write `$this->name` — it works. But if I write `self::$name` — I get an error. And with the static property it's the opposite: `self::$count` works, but `$this->count` doesn't. I read the manual, but it's too complicated. Explain in simple terms: when should I use `self::`, and when