PHP OOP Objects
After declaring the House class you can create objects from it.
Here's our house class.
After the class declaration you can create instances from it.
Now each object is created having the default values of the class. You can check it by echoing the color of each object.
Both would echo out the default value black.
-> is the object operator, which is used to access properties and methods of an object.
Tip: When accessing properties and methods of an object through the object operator, the dollar sign $ is not used with the property or method name.
You can also change the default property values of the class to make each house unique.
Now, the color of my house is red while the color of my friend's house is yellow.
What is the difference between classes and objects?
A class is a structure with default values and methods (Blueprint for a house).
Multiple objects can be created from a class. (Houses built from the blueprint)
Each object has all the properties and methods defined in the class, but they can have different property values.