1

why am I getting these errors? Undefined variable: num1 Cannot access empty property

class sum{
    public $num1=1;
public function fun($num2){
     return $this->$num1+$num2;
    }
}
$number = new sum();
echo $number->fun(3);
Sina
  • 33
  • 3

1 Answers1

1
class sum{
   public $num1=1;
   public function fun($num2){
        return $this->num1+$num2;
          //removed $^^
   }
}
$number = new sum();
echo $number->fun(3);
Narendrasingh Sisodia
  • 21,247
  • 6
  • 47
  • 54