class Magic{
public $a="i";
public $b=array("a"=>"A","b"=>"B","c"=>"C");
public $c=array(1,2,3);
public function __get($v)
{
echo "<br/>get->$v";
return $this->b[$v];
}
public function __set($var,$val)
{
echo "<br/>set->$var: $val,";
$this->$var=$val;
}
}
$m=new Magic();
echo $m->a." , ".$m->b." ,".$m->c." ,";
$m->c="CC";
echo $m->a." , ".$m->b." ,".$m->c;
Output:i , Array ,Array ,i , Array ,CC
Now, I modify the visibility to protected for variable $b and $c.
Output: bci , B ,C ,c: CC,bci , B ,C
As far as I understand _get and_set is called for undefined var .So, when access modifier or visibility is set to protected why __get() is called !.
Can someone explain ….. I am not able to understand this.
From the manual
A protected / private property is considered inaccessible from an external scope.