What is the difference between Instance and Object in PHP?

Class is a “blueprint” that can use to “instantiate” different “object”. Let’s go with a simple example for details:

Consider a Class called Car that may contain different properties and methods.

Let’s create a instance for storing Car Object values using the Car Class as a “blueprint” like $carone = new Car(); You can create many “instance” using that “blueprint”.

The “new” keyword tells PHP that you want a new “instance” of the Car class.

Now you can set the values for the different properties and can access the methods like $carone->brand = ‘Tesla’; $carone->start();

So after storing value in instance, now $carone treated as Object.

Leave a Reply

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