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.