From the course: PHP: Object-Oriented Programming
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Class methods - PHP Tutorial
From the course: PHP: Object-Oriented Programming
Class methods
- [Instructor] In this movie, we're going to learn to add methods to our class definitions. A method is just a function inside the class to perform object actions. When we're working with procedural or non-object oriented programming we just call them functions. When they're inside a class they're correctly called methods. Now you're going to see those two terms used interchangeably all time, even in the PHP documentation. So don't get too hung up on it. A method is just a function inside a class. And in fact, you define them inside the class just like regular functions. Let's take a look. Here, I have a class definition for person. It has a couple of properties for first name and last name. And then I have a method. Our method is defined using the same function keyword that we would normally use, followed by the name of the function, parentheses to surround any arguments that might be there, and then curly braces…
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.