php - sum of 2 number with object and method -


why 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); 

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

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -