Category: PHP

In this tutorial, we’ll start understanding of self and this in PHP & will see when to use self and $this in PHP while development & will understand how can we use self & $this in various situations.

In OOP, to access these class components, we can use either $this OR self in PHP.

Okay, so in this example, we have created a book class in which we have defined one static variable ($bookId) and to access it, we have defined getBookId() method.

this is the pseudo-variable created as soon the object of the class is created and is available to use once that class method is called from within an object context.

So, basically, we need to make sure that while creating any class, what is the purpose of this class and how different components of the class will help in making that class complete.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners