Example 1

class tv
{
    public $model;
    public $rate;

    function ratePlu($r)
    {
        $this -> rate = $r;
        $this -> rate += 2000;
    }
    function rateMin($r)
    {
        $this -> rate = $r;
        $this -> rate -= 1250;
    }
}
$tv1 = new tv();

$tv1->ratePlu(5500);
echo $tv1->rate;

$tv1->rateMin(7250);
echo $tv1->rate;

Result

7500
6000

Example 2

class tv1
{
    public $model;
    public $rate;

    function ratePlu($r, $i)
    {
        $this -> rate = $r;
        $this -> rate += $i;
    }
    function rateMin($r, $i)
    {
        $this -> rate = $r;
        $this -> rate -= $i;
    }
}
$tv1 = new tv1();
$tv1->ratePlu(5500, 1250);
echo $tv1->rate;

$tv1->rateMin(7250, 1250);
echo $tv1->rate;

Result

6750
6000

Example 3 (Construct Function)

class tv3
{
    public $rate;
    function ratePlu1()
    {
        $this -> rate += 1500;
    }
    function rateMin1()
    {
        $this -> rate -= 1200;
    }
    function __construct()
    {
        $this -> rate = 3500;
    }
}
$tv3 = new tv3;
echo $tv3->rate;

$tv3->ratePlu1();
echo $tv3->rate;

$tv3->rateMin1();
echo $tv3->rate;    
Actual Rate is ...... 3500...... as in Construct Function
Value after calling Function ratePlu1......5000
Value after calling Function rateMin1......3800

Example 4 (Object Inheritance)

When you extend a class, the subclass inherits all of the public and protected methods from the parent class. Unless a class overrides those methods, they will retain their original functionality.

class tv4
{
    public $rate;

    function ratePlus()
        {
            $this -> rate += 1700;
        }
    function __construct()
        {
            $this -> rate = 3500;
        }
}
class ext1 extends tv4
{
    function __construct()
        {
            $this -> rate = 6200;
        }
}

$tv4 = new ext1;
echo $tv4 -> rate;

$tv4->ratePlus();
echo $tv4->rate;

Result

6200
7900

Getter and Setter Functions