Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In this chapter, I'm going to introduce some key concepts about object-oriented programming. Starting with what objects are, I'll then define classes. Like any technique, it's good to know why you should use object-oriented programming. And, there are a number of reasons. Finally, I will give a little history of object-oriented PHP, as it's evolved quite a bit over the years. If I were to define object-oriented programming as programming with objects, that wouldn't be very helpful at all. Instead, I'll start small, and build up. In computer science, a primitive data type is a basic, simple type of data provided by a programming language.
Think of it as a building block, as larger, more complex structures can be built using primitives. Some examples of primitives in PHP include Booleans, which are a logical data type containing either True or False; integers, which are a numeric data type that holds a whole number without any fractions. Examples include -6 and 42. Getting slightly more complex are floating-point numbers. Floats are a numeric data type as well, but they can have fractional values. Examples include 98.6 and -25, as floats don't have to have a fractional value.
Finally, strings, which contain a sequence of characters. An example of a string would be the phrase "hello, world." Using the building blocks of primitives, more complex data structures can be built, which are known as objects. An object can contain multiple data types, each with their own values. There is no restriction on the number or the combination of data types. You can have two strings, or a float and a Boolean, or no data types at all. To help illustrate my point, I'll compare primitives to objects. For example, consider a string containing the word "Toronto." It's 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 the street number, city, and subdivision. The value stored for the city could be a string containing the word "Toronto." Each value in an object is stored as a property, which I'll explore in a moment.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99928 Viewers
56 Video lessons · 113024 Viewers
71 Video lessons · 81870 Viewers
131 Video lessons · 39286 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.