Loading, please wait...

A to Z Full Forms and Acronyms

How to create a class with setter and getter functions in PHP | PHP programs

Jan 19, 2022 PHP, 1061 Views
How to create a class with setter and getter functions in PHP | PHP programs

How to create a class with setter and getter functions in PHP | PHP programs

We will define a class Sample with setter and getter functions.

<?php

class Start
{
    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 Start();

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

echo "A: " . $S->GetA() . '<br>';
echo "B: " . $S->GetB() . '<br>';
?>
A to Z Full Forms and Acronyms