What is the difference between Instance and Object in PHP?

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

Consider a Class called a Car that may contain different properties(brand, model, ….) and methods( start(), stop(), …).

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

The “new” keyword tells PHP 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 an instance, $carone is treated as Object.

Leave a Reply

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