An Object data type stores data and also information on how to process the data known as a method.
As an example a car could be considered an object.
The car has certain properties such as make model color weight and so on.
A method would be considered anything that the car can do such as travel turn stop or slow down.
As a rule an object must be explicitly declared the first step to creating an object is to create a
class the class is the set of properties or variables that are tied to an object in this example.
We have the class person next.
We've defined some properties that the person has the person object has three properties a first name
a last name in an age you'll notice in front of each property we have an assignment called public.
There are three different types of assignments including public private and protected
next.
We've constructed a function that tells our properties what values will be assigned to the variables
first name last name and age in this case.
Each time a new person is created is seen here.
The first value contained inside the parenthesis after the new person declaration will be the first
name.
The second value inside the parenthesis will be the last name and the third will be the age each variable
here.
Person one person to creates a new person each person has their own unique set of information.
We have a method inside our class and the method is a function tied to an object this method which we've
called Hello will output a sentence with the person's first name last name in age we've called on this
function at the end of our script here
we can see the statement echo Person 1 Hello.
We also have echo person 2 Hello in our web browser we can see the values of the properties first First
Name Last Name and age have been output ID based on the number of new persons we created which in this
case was to
and that is how an object works.
Note that these values would typically be derived from a database.