I'm trying to build a function inside a PHP class, however whenever I invoke the function, I am only returning the first variable.
class Nums
{
private $a = 7;
private $b = 8;
public function sum()
{
return $this->a + $this->b;
}
public function __set($name,$value) {
switch($name) {
case 'a':
return $this->setA($value);
case 'b':
return $this->setB($value);
}
}
public function __get($name) {
switch($name) {
case 'a':
return $this->getA();
case 'b':
return $this->getB();
}
}
private function setA($i) {
$this->a = $i;
}
private function getA() {
return $this->$a;
}
private function setB($i) {
$this->b = $i;
}
private function getB() {
return $this->$b;
}
}
Am I doing something wrong here, because I can't really see what is wrong with this logic.