PHP program to create a class with setter and getter functions

bookmark

<?php
//PHP program to create a class with
//setter and getter functions.
class Sample
{
    private $A;
    private $B;

    public function GetA()
    {
        return $this->A;
    }

    public function GetB()
    {
        return $this->B;
    }

    public function SetA($A)
    {
        $this->A = $A;
    }

    public function SetB($B)
    {
        $this->B = $B;
    }
}

$S = new Sample();

$S->SetA(10);
$S->SetB(20);

echo "A: " . $S->GetA() . '<br>';
echo "B: " . $S->GetB() . '<br>';
?>


Output
A: 10
B: 20