php - sum of 2 number with object and method -
this question has answer here:
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
Post a Comment