Object: In computer science a primitive data type is a basic type of data provided by programming language. Some examples of primitive data types in PHP include Booleans, which are a logical data type containing true or false; floating-point numbers, also known as floats, which are numeric data type that have fractional values–examples include 36.2 and -25; integers are a numeric data type that hold a whole number without any fractions–examples include -6 and 42; and strings, which contain a sequence of characters such as “ecomputernotes.com.” With that in mind, an object is a complex data structure along with attributes and behaviors.
In contrast with the basic data types, such as a primitive that consists of a single value, an object can have multiple data types, each with their own values.
For example, a string containing the words “Toronto” is a simple data type with a single value.
In comparison, an object representing a physical address may have multiple data types, each with their own values, such as a street number, city, and subdivision.
The value stored for the city could be a string containing the words Toronto. Each value in an object is known as a property, which will be explored in greater depth in a later segment.
Class: A class is a blueprint that defines the attributes and behaviors that makes up an object. Objects are instances of a class, meaning each occurrence of an object of a particular class has all the attributes and behaviors of that class.
The individual attributes will be the same, but the contents of those attributes may differ. Each class modularizes program functions by separating distinct features with as little overlap as possible. Using the example of a physical address again, you can define a class for an address.
The class address has several attributes, like the city and subdivision, and has a behavior of being able to look up a postal code given these attributes; therefore, any object of class address will have those attributes and behavior.
Conceptualize two objects that are instances of an address.
As each object is an address, I know that they should have it least the city and subdivision, so I can look up the postal code. I can’t anticipate the contents of the object attributes, but I do know that they will be in a particular format, and how to access them.