What is the difference between Object and Class in PHP? I ask because, I don't really see the point to both of them.
Can you tell me the difference with a good example?
What is the difference between Object and Class in PHP? I ask because, I don't really see the point to both of them.
Can you tell me the difference with a good example?
For the new developers:
Class
A class is a collection of method and variables
Object
Object is a instance of a class (when you want to use your class and the thing you create)
I assume you have read the manual on basic PHP OOP.
A class is what you use to define the properties, methods and behavior of objects. Objects are the things you create out of a class. Think of a class as a blueprint, and an object as the actual building you build by following the blueprint (class). (Yes, I know the blueprint/building analogy has been done to death.)
The objects here are distinct (A and B), but they are both objects of the
MyClass
class. Going back to the blueprint/building analogy, think of it as using the same blueprint to build two different buildings.Here's another snippet that actually talks about buildings if you need a more literal example: