I am trying to learn php class. I am getting confused about which properties should have to declare inside class. I am giving a simple example to understand the situation:
class main{
var $a=5;
var $b;
function add($c){
return $this->a + $this->b + $c;
}
}
$load = new main();
$load-> $b=10;
echo $load->add(20); //will output 35
In the above case, please see that I did not declare property $c inside class. It is directly accessing from the call $load->add(20) and it is working well. My question is although this is working, but is it right way or I have to declare the $c property in this case? NB: May be this is working due to set magic method of oop, not sure.