The $this Keyword — a practical guide to PHP $this with clear examples you can reuse in real projects.
OOP Tutorial Series (12/65). Prefer one article? Read the complete OOP tutorial.
Short description
Inside an instance method, `$this` refers to the object the method was called on.
$this usage
class Account {
private float $balance = 0;
public function deposit(float $amount): void {
$this->balance += $amount;
}
public function getBalance(): float {
return $this->balance;
}
}