Given MyCalculator class
class MyCalculator
{
public float $a, $b, $c,
public MyCalculator $result;
public function __construct ($a, $b)
{
$this->a = $a;
$this->b = $b;
$this->result = new MyCalculator($this->c, 0)
}
public function add()
{
$this->result->c = $this->a + $this->b;
return $this->result->c;
}
public function divideBy($num)
{
$this->result->c = $this->result->c / $num;
return $this->result->c;
}
}
$calc = new MyCalculator(12, 6);
In my code works good either:
echo $calc->Add() // Displays: 15
or
echo $calc->Add()->DivideBy(3) // Displays: 5 ((6+9)/3=5)
But I cannot make them working both!