Course Title: Web Development Masterclass
Course Link: http://youaccel.com/admin/cdisplay.ph...
Facebook: / youaccel
Twitter: / youaccel
Website: http://youaccel.com
Tutorial Content:
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. A car has certain properties such as make, model, color, weight, etc.
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 person has.
The person object, has three properties, a first name, a last name and age.
You will notice in front of each property we have an assignment, called public. There are three different types of assignments including, public, private and protected.
A public assignment means the property can be accessed everywhere.
A private assignment means it can only be accessed by the class that defines it.
A protected assignment means it can be accessed only within the class itself and by inherited parent classes.
Next we've constructed a function that tells our properties what values will be assigned to the variables, firstname, lastname and age.
In this case, each time a new person is created, the first value inside the parenthesis will be the objects firstname, the second value will be the last name, followed by age..
As a demonstration we have created two variables, person1 and person2. person1 creates a new person with the name John Smith, who is 25 years old.
person2 does the same with a different name and age.
We have a method inside our class. A method is a function tied to an object.
This method, which we have called hello, will output a sentence with the persons first name, last name and age.
We have called on this function at the end of our script. We can see the statement echo person1 hello. We also have echo person2 hello.
In our web browser we can see the values of the properties firstname, lastname and age have been outputted based on the number of new persons we created, which in this case is two.
Auf dieser Seite können Sie das Online-Video PHP Objects | Tutorial mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer YouAccel 09 Mai 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 12 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!