Loading video...
Object Methods
- Classes can define functions, known as object methods, that instances of the class can execute.
- An object method is defined within the curly braces of a class definition using the same syntax used when creating user-defined functions.
- Object methods are called using the arrow operator
->. An object variable is followed by->, the name of the method, and a set of parentheses, which can optionally include any arguments to be passed to the object method:$person1 = new Person();
$person1->hello(); // object method requiring no arguments
$person1->helloWithArg($arg1); // object method requiring arguments - Object methods can return values just like user-defined functions.
$thisis a special variable in PHP that is used within a class’s methods to refer to the current instance of a class.- A getter method retrieves the value of an object’s property.
- A setter method sets the value of an object’s property.
- An object method’s return value can be output within double-quoted strings using curly brace syntax:
$person1 = new Person();
$person1->setFirstName(‘Joe’);
echo “First: {$person1->getFirstName()}”; - Object methods can call other object methods of the same object instance by using the
$thisvariable.
Object Methods
Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

































Start Learning Now
Our free lessons will get you started (Flash® 10 required).
Sign up for Educator.comGet immediate access to our entire library.
Features Overview