Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
OOP

The $this Keyword

Use $this to access the current object’s properties and methods.

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;
    }
}

Leave a reply

Your email address will not be published. Required fields are marked *