From the course: Learning PHP
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
What are objects and classes? - PHP Tutorial
From the course: Learning PHP
What are objects and classes?
- [Instructor] Functions are a great way to have consistency throughout your code base. And you can reuse useful code. Another way to do that is with classes. A class is a way of grouping variables and functions together as a single referenceable unit. The powerful part of classes is you can have more than one as long as you name them differently. The different instantiations or versions of these classes are called objects. And the benefit is that you can have a single set of variables and functions and based on the object, reference them. PHP has many built-in functions but we can also write our own. So if you have a Person class, you can use it to create two Person objects, Alice and Bob. They'll have the same variables and functions available to them but the information will be different. You can think of classes as the mold for a toy. Then each individual toy with different color plastic and paint are the objects.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
What are functions?5m 11s
-
(Locked)
Using built-in functions4m 40s
-
(Locked)
Writing custom functions7m 10s
-
(Locked)
Union typing variables2m
-
(Locked)
Optional or named arguments5m 23s
-
(Locked)
Anonymous functions4m 32s
-
(Locked)
What are objects and classes?3m 21s
-
(Locked)
Defining a simple person class (update for PHP 8.0)3m 19s
-
(Locked)
Using the person class3m 25s
-
(Locked)
Challenge: Sort an array of objects46s
-
(Locked)
Solution: Sort an array of objects3m 26s
-
-
-
-
-
-