🐘 PHP Beginner

What is $this in PHP?

Answer

$this is a pseudo-variable available inside non-static class methods that refers to the current object instance being operated on. It is used to access instance properties and methods: $this->name accesses the name property, and $this->getName() calls the getName() method. $this is not available in static methods because static methods belong to the class, not an instance. Attempting to use $this in a static context produces a notice. The equivalent for referencing the class itself (including static properties and methods) is the self::, static::, and parent:: keywords.