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

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners