Пример #1
0
    public $a;
    public $b;
    public $c;
    function __construct($num1, $num2)
    {
        $this->a = $num1;
        $this->b = $num2;
    }
    function add()
    {
        $this->c = $this->a + $this->b;
        echo $this->c;
    }
    function substract()
    {
        $this->c = $this->a - $this->b;
        echo $this->c;
    }
}
$num1 = $_POST["num1"];
$num2 = $_POST["num2"];
$p = new calculator($num1, $num2);
$oper = $_POST["oper"];
switch ($oper) {
    case "+":
        $p->add();
        break;
    case "-":
        $p->substract();
        break;
}