PHP & OOP: Methods of a class

In object-oriented programming, the member functions of a class are also called methods of the class.

If you read any literature related to object-oriented programming, you will come across this word frequently.

Look at the following example:


class PopStar
    public $person;
    public $salary;
    public $album;

    public function setSalary()
        $this->salary = 10000;

    public function getSalary()
        echo $this->salary;

$star = new PopStar();
echo "The pop star's salary is:";
echo "<br>";


There are 2 methods setSalary() and getSalary() in the above PopStar class.

From the code above, we can say that we are using the method setSalary() to set the salary of the pop star and method getSalary() to get the salary of the star.

Series Navigation<< PHP & OOP: Properties of a class
PHP & OOP: Constructors and destructors >>