I am trying to work out why the answer to a PHP quiz question is what it is.
The code below prints out: b,c,A,B,C,
I just can't seem to get my head round how it works, would anyone be able to talk me through it quickly?
Code:
<?php
class Magic {
public $a = "A";
protected $b = array("a" => "A", "b" => "B", "c" => "C");
protected $c = array (1,2,3);
public function __get($V) {
echo "$V,";
return $this->b[$V];
}
public function __set($var, $val) {
echo "$var: $val,";
echo $this->$var = $val;
}
}
$m = new Magic();
echo $m->a . "," . $m->b . "," . $m->c . ",";
?>